github.com/hoffie/larasync@v0.0.0-20151025221940-0384d2bddcef/repository/util_test.go (about) 1 package repository 2 3 import ( 4 "os" 5 "path/filepath" 6 7 . "gopkg.in/check.v1" 8 ) 9 10 type UtilTests struct { 11 dir string 12 } 13 14 var _ = Suite(&UtilTests{}) 15 16 func (t *UtilTests) SetUpTest(c *C) { 17 t.dir = c.MkDir() 18 } 19 20 func (t *UtilTests) TestRepoRootInvalid(c *C) { 21 r, err := GetRoot(t.dir) 22 c.Assert(err, NotNil) 23 c.Assert(r, Equals, "") 24 } 25 26 func (t *UtilTests) TestRepoRootValid(c *C) { 27 path := filepath.Join(t.dir, ".lara") 28 err := os.Mkdir(path, 0700) 29 c.Assert(err, IsNil) 30 r, err := GetRoot(t.dir) 31 c.Assert(err, IsNil) 32 c.Assert(r, Equals, t.dir) 33 } 34 35 func (t *UtilTests) TestRepoRootSubdirValid(c *C) { 36 err := os.Mkdir(filepath.Join(t.dir, ".lara"), 0700) 37 c.Assert(err, IsNil) 38 err = os.Mkdir(filepath.Join(t.dir, "foo"), 0700) 39 c.Assert(err, IsNil) 40 r, err := GetRoot(filepath.Join(t.dir, "foo")) 41 c.Assert(err, IsNil) 42 c.Assert(r, Equals, t.dir) 43 } 44 45 func (t *UtilTests) TestRepoRootNoLeadingSlash(c *C) { 46 _, err := GetRoot(filepath.Join("non/existing/dir")) 47 c.Assert(err, NotNil) 48 } 49 50 func (t *UtilTests) TestFormatUUID(c *C) { 51 x := make([]byte, 32) 52 c.Assert(formatUUID(x), Equals, "0000000000000000000000000000000000000000000000000000000000000000") 53 }