Пример #1
0
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))
}
Пример #2
0
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)
}
Пример #3
0
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)
}
Пример #4
0
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)
}
Пример #5
0
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))
}
Пример #6
0
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)
}