func (*SymlinkSuite) TestReplace(c *gc.C) { target, err := symlink.GetLongPathAsString(c.MkDir()) c.Assert(err, gc.IsNil) target_second, err := symlink.GetLongPathAsString(c.MkDir()) c.Assert(err, gc.IsNil) link := filepath.Join(target, "link") _, err = os.Stat(target) c.Assert(err, gc.IsNil) _, err = os.Stat(target_second) c.Assert(err, gc.IsNil) err = symlink.New(target, link) c.Assert(err, gc.IsNil) link_target, err := symlink.Read(link) c.Assert(err, gc.IsNil) c.Assert(link_target, gc.Equals, filepath.FromSlash(target)) err = symlink.Replace(link, target_second) c.Assert(err, gc.IsNil) link_target, err = symlink.Read(link) c.Assert(err, gc.IsNil) c.Assert(link_target, gc.Equals, filepath.FromSlash(target_second)) }
func (*SymlinkSuite) TestLongPath(c *gc.C) { programFiles := `C:\PROGRA~1` longProg := `C:\Program Files` target, err := symlink.GetLongPathAsString(programFiles) c.Assert(err, gc.IsNil) c.Assert(target, gc.Equals, longProg) }
func (*SymlinkSuite) TestIsSymlinkFalseFolder(c *gc.C) { target, err := symlink.GetLongPathAsString(c.MkDir()) c.Assert(err, gc.IsNil) _, err = os.Stat(target) c.Assert(err, gc.IsNil) isSymlink, err := symlink.IsSymlink(target) c.Assert(err, gc.IsNil) c.Assert(isSymlink, jc.IsFalse) }
func (*SymlinkSuite) TestIsSymlinkFolder(c *gc.C) { target, err := symlink.GetLongPathAsString(c.MkDir()) c.Assert(err, gc.IsNil) link := filepath.Join(target, "link") _, err = os.Stat(target) c.Assert(err, gc.IsNil) err = symlink.New(target, link) c.Assert(err, gc.IsNil) isSymlink, err := symlink.IsSymlink(link) c.Assert(err, gc.IsNil) c.Assert(isSymlink, jc.IsTrue) }
func (*SymlinkSuite) TestCreateSymLink(c *gc.C) { target, err := symlink.GetLongPathAsString(c.MkDir()) c.Assert(err, gc.IsNil) link := filepath.Join(target, "link") _, err = os.Stat(target) c.Assert(err, gc.IsNil) err = symlink.New(target, link) c.Assert(err, gc.IsNil) link, err = symlink.Read(link) c.Assert(err, gc.IsNil) c.Assert(link, gc.Equals, filepath.FromSlash(target)) }
func (*SymlinkSuite) TestIsSymlinkFile(c *gc.C) { dir, err := symlink.GetLongPathAsString(c.MkDir()) c.Assert(err, gc.IsNil) target := filepath.Join(dir, "file") err = ioutil.WriteFile(target, []byte("TOP SECRET"), 0644) c.Assert(err, gc.IsNil) link := filepath.Join(dir, "link") _, err = os.Stat(target) c.Assert(err, gc.IsNil) err = symlink.New(target, link) c.Assert(err, gc.IsNil) isSymlink, err := symlink.IsSymlink(link) c.Assert(err, gc.IsNil) c.Assert(isSymlink, jc.IsTrue) }