| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
package osfs |
| 5 |
|
| 6 |
import ( |
| 7 |
"fmt" |
| 8 |
"os" |
| 9 |
"path/filepath" |
| 10 |
"reflect" |
| 11 |
"testing" |
| 12 |
|
| 13 |
"github.com/go-git/go-billy/v5" |
| 14 |
"github.com/go-git/go-billy/v5/helper/chroot" |
| 15 |
"github.com/go-git/go-billy/v5/test" |
| 16 |
|
| 17 |
. "gopkg.in/check.v1" |
| 18 |
) |
| 19 |
|
| 20 |
func Test(t *testing.T) { TestingT(t) } |
| 21 |
|
| 22 |
type OSSuite struct { |
| 23 |
test.FilesystemSuite |
| 24 |
path string |
| 25 |
tempCounter int |
| 26 |
} |
| 27 |
|
| 28 |
var _ = Suite(&OSSuite{}) |
| 29 |
|
| 30 |
func (s *OSSuite) SetUpTest(c *C) { |
| 31 |
s.tempCounter++ |
| 32 |
s.path = fmt.Sprintf("test_%d", s.tempCounter) |
| 33 |
s.FilesystemSuite = test.NewFilesystemSuite(New(s.path)) |
| 34 |
} |
| 35 |
|
| 36 |
func (s *OSSuite) TestOpenDoesNotCreateDir(c *C) { |
| 37 |
_, err := s.FS.Open("dir/non-existent") |
| 38 |
c.Assert(err, NotNil) |
| 39 |
|
| 40 |
_, err = s.FS.Stat(filepath.Join(s.path, "dir")) |
| 41 |
c.Assert(os.IsNotExist(err), Equals, true) |
| 42 |
} |
| 43 |
|
| 44 |
func (s *OSSuite) TestCapabilities(c *C) { |
| 45 |
_, ok := s.FS.(billy.Capable) |
| 46 |
c.Assert(ok, Equals, true) |
| 47 |
|
| 48 |
caps := billy.Capabilities(s.FS) |
| 49 |
c.Assert(caps, Equals, billy.DefaultCapabilities&^billy.LockCapability) |
| 50 |
} |
| 51 |
|
| 52 |
func TestDefault(t *testing.T) { |
| 53 |
want := &chroot.ChrootHelper{} |
| 54 |
got := Default |
| 55 |
|
| 56 |
if reflect.TypeOf(got) != reflect.TypeOf(want) { |
| 57 |
t.Errorf("wanted Default to be %T got %T", want, got) |
| 58 |
} |
| 59 |
} |
| 60 |
|
| 61 |
func TestNewAPI(t *testing.T) { |
| 62 |
_ = New("/") |
| 63 |
} |