func (s *ToolsSuite) testEnsureSymlinks(c *gc.C, dir string) { jujudPath := filepath.Join(s.toolsDir, names.Jujud) err := ioutil.WriteFile(jujudPath, []byte("assume sane"), 0755) c.Assert(err, jc.ErrorIsNil) assertLink := func(path string) time.Time { target, err := symlink.Read(path) c.Assert(err, jc.ErrorIsNil) c.Assert(target, jc.SamePath, jujudPath) fi, err := os.Lstat(path) c.Assert(err, jc.ErrorIsNil) return fi.ModTime() } // Check that EnsureSymlinks writes appropriate symlinks. err = jujuc.EnsureSymlinks(dir) c.Assert(err, jc.ErrorIsNil) mtimes := map[string]time.Time{} for _, name := range jujuc.CommandNames() { tool := filepath.Join(s.toolsDir, name) mtimes[tool] = assertLink(tool) } // Check that EnsureSymlinks doesn't overwrite things that don't need to be. err = jujuc.EnsureSymlinks(s.toolsDir) c.Assert(err, jc.ErrorIsNil) for tool, mtime := range mtimes { c.Assert(assertLink(tool), gc.Equals, mtime) } }
func (suite *HelpToolSuite) TestHelpTool(c *gc.C) { expectedNames := jujuc.CommandNames() output := badrun(c, 0, "help-tool") lines := strings.Split(strings.TrimSpace(output), "\n") for i, line := range lines { lines[i] = strings.Fields(line)[0] } if runtime.GOOS == "windows" { for i, command := range lines { lines[i] = command + ".exe" } } c.Assert(lines, gc.DeepEquals, expectedNames) }