github.com/hoffie/larasync@v0.0.0-20151025221940-0384d2bddcef/repository/tracker/nibSearchResponse_test.go (about) 1 package tracker 2 3 import ( 4 "io/ioutil" 5 "path/filepath" 6 7 . "gopkg.in/check.v1" 8 ) 9 10 var _ = Suite(&NIBSearchResponseTest{}) 11 12 type NIBSearchResponseTest struct { 13 dirPath string 14 } 15 16 func (t *NIBSearchResponseTest) SetUpTest(c *C) { 17 t.dirPath = c.MkDir() 18 } 19 20 func (t *NIBSearchResponseTest) newResponse(NIBID string, path string) *NIBSearchResponse { 21 return NewNIBSearchResponse(NIBID, path, t.dirPath) 22 } 23 24 func (t *NIBSearchResponseTest) TestFileExistsNegative(c *C) { 25 resp := t.newResponse("asdf", "test") 26 c.Assert(resp.FileExists(), Equals, false) 27 } 28 29 func (t *NIBSearchResponseTest) TestFileExistsPositive(c *C) { 30 resp := t.newResponse("asdf", "test") 31 err := ioutil.WriteFile(resp.AbsPath(), []byte("test"), 0700) 32 c.Assert(err, IsNil) 33 c.Assert(resp.FileExists(), Equals, true) 34 } 35 36 func (t *NIBSearchResponseTest) TestAbsPath(c *C) { 37 filePath := "test" 38 resp := t.newResponse("asdf", filePath) 39 err := ioutil.WriteFile(resp.AbsPath(), []byte("test"), 0700) 40 c.Assert(err, IsNil) 41 expectedPath := filepath.Join(t.dirPath, filePath) 42 expectedPath, err = filepath.EvalSymlinks(expectedPath) 43 c.Assert(err, IsNil) 44 c.Assert(resp.AbsPath(), Equals, expectedPath) 45 }