| 1 | package polyfill |
| 2 | |
| 3 | import ( |
| 4 | "path/filepath" |
| 5 | "testing" |
| 6 | |
| 7 | "github.com/go-git/go-billy/v5" |
| 8 | "github.com/go-git/go-billy/v5/test" |
| 9 | |
| 10 | . "gopkg.in/check.v1" |
| 11 | ) |
| 12 | |
| 13 | func Test(t *testing.T) { TestingT(t) } |
| 14 | |
| 15 | var _ = Suite(&PolyfillSuite{}) |
| 16 | |
| 17 | type PolyfillSuite struct { |
| 18 | Helper billy.Filesystem |
| 19 | Underlying billy.Filesystem |
| 20 | } |
| 21 | |
| 22 | func (s *PolyfillSuite) SetUpTest(c *C) { |
| 23 | s.Helper = New(&test.BasicMock{}) |
| 24 | } |
| 25 | |
| 26 | func (s *PolyfillSuite) TestTempFile(c *C) { |
| 27 | _, err := s.Helper.TempFile("", "") |
| 28 | c.Assert(err, Equals, billy.ErrNotSupported) |
| 29 | } |
| 30 | |
| 31 | func (s *PolyfillSuite) TestReadDir(c *C) { |
| 32 | _, err := s.Helper.ReadDir("") |
| 33 | c.Assert(err, Equals, billy.ErrNotSupported) |
| 34 | } |
| 35 | |
| 36 | func (s *PolyfillSuite) TestMkdirAll(c *C) { |
| 37 | err := s.Helper.MkdirAll("", 0) |
| 38 | c.Assert(err, Equals, billy.ErrNotSupported) |
| 39 | } |
| 40 | |
| 41 | func (s *PolyfillSuite) TestSymlink(c *C) { |
| 42 | err := s.Helper.Symlink("", "") |
| 43 | c.Assert(err, Equals, billy.ErrNotSupported) |
| 44 | } |
| 45 | |
| 46 | func (s *PolyfillSuite) TestReadlink(c *C) { |
| 47 | _, err := s.Helper.Readlink("") |
| 48 | c.Assert(err, Equals, billy.ErrNotSupported) |
| 49 | } |
| 50 | |
| 51 | func (s *PolyfillSuite) TestLstat(c *C) { |
| 52 | _, err := s.Helper.Lstat("") |
| 53 | c.Assert(err, Equals, billy.ErrNotSupported) |
| 54 | } |
| 55 | |
| 56 | func (s *PolyfillSuite) TestChroot(c *C) { |
| 57 | _, err := s.Helper.Chroot("") |
| 58 | c.Assert(err, Equals, billy.ErrNotSupported) |
| 59 | } |
| 60 | |
| 61 | func (s *PolyfillSuite) TestChmod(c *C) { |
| 62 | ch, ok := s.Helper.(billy.Chmod) |
| 63 | c.Assert(ok, Equals, true) |
| 64 | |
| 65 | err := ch.Chmod("", 0o444) |
| 66 | c.Assert(err, Equals, billy.ErrNotSupported) |
| 67 | } |
| 68 | |
| 69 | func (s *PolyfillSuite) TestRoot(c *C) { |
| 70 | c.Assert(s.Helper.Root(), Equals, string(filepath.Separator)) |
| 71 | } |
| 72 | |
| 73 | func (s *PolyfillSuite) TestCapabilities(c *C) { |
| 74 | testCapabilities(c, new(test.BasicMock)) |
| 75 | testCapabilities(c, new(test.OnlyReadCapFs)) |
| 76 | testCapabilities(c, new(test.NoLockCapFs)) |
| 77 | } |
| 78 | |
| 79 | func testCapabilities(c *C, basic billy.Basic) { |
| 80 | baseCapabilities := billy.Capabilities(basic) |
| 81 | |
| 82 | fs := New(basic) |
| 83 | capabilities := billy.Capabilities(fs) |
| 84 | |
| 85 | c.Assert(capabilities, Equals, baseCapabilities) |
| 86 | } |