From: Mathias Gibbens Description: Remove use of the juju/utils library (break bi-directional dependency loop) Forwarded: https://github.com/juju/testing/issues/161 diff --git a/cmd.go b/cmd.go index b4f1135..bdf6a17 100644 --- a/cmd.go +++ b/cmd.go @@ -13,7 +13,6 @@ import ( "strconv" "strings" - "github.com/juju/utils/v4" gc "gopkg.in/check.v1" jc "github.com/juju/testing/checkers" @@ -166,7 +165,7 @@ func AssertEchoArgs(c *gc.C, execName string, args ...string) { // Create expected output string expected := execName for _, arg := range args { - expected = fmt.Sprintf("%s %s", expected, utils.ShQuote(arg)) + expected = fmt.Sprintf("%s %s", expected, `'` + strings.Replace(arg, `'`, `'"'"'`, -1) + `'`) } actual := ReadEchoArgs(c, execName) c.Assert(actual, gc.Equals, expected) diff --git a/home.go b/home.go index 66d0ab6..ce81773 100644 --- a/home.go +++ b/home.go @@ -8,7 +8,6 @@ import ( "os" "path/filepath" - "github.com/juju/utils/v4" gc "gopkg.in/check.v1" jc "github.com/juju/testing/checkers" @@ -27,7 +26,7 @@ type FakeHome struct { func MakeFakeHome(c *gc.C) *FakeHome { fakeHome := c.MkDir() - err := utils.SetHome(fakeHome) + err := os.Setenv("HOME", fakeHome) c.Assert(err, jc.ErrorIsNil) sshPath := filepath.Join(fakeHome, ".ssh") @@ -45,7 +44,7 @@ func MakeFakeHome(c *gc.C) *FakeHome { func (h *FakeHome) AddFiles(c *gc.C, files ...TestFile) { for _, f := range files { - path := filepath.Join(utils.Home(), f.Name) + path := filepath.Join(os.Getenv("HOME"), f.Name) err := os.MkdirAll(filepath.Dir(path), 0700) c.Assert(err, gc.IsNil) err = ioutil.WriteFile(path, []byte(f.Data), 0666) @@ -81,7 +80,7 @@ func (h *FakeHome) FileExists(path string) bool { // HomePath joins the specified path snippets and returns // an absolute path under Juju home. func HomePath(names ...string) string { - all := append([]string{utils.Home()}, names...) + all := append([]string{os.Getenv("HOME")}, names...) return filepath.Join(all...) } @@ -114,10 +113,10 @@ func (s *FakeHomeSuite) TearDownSuite(c *gc.C) { func (s *FakeHomeSuite) SetUpTest(c *gc.C) { s.CleanupSuite.SetUpTest(c) s.LoggingSuite.SetUpTest(c) - home := utils.Home() + home := os.Getenv("HOME") s.Home = MakeFakeHome(c) s.AddCleanup(func(*gc.C) { - err := utils.SetHome(home) + err := os.Setenv("HOME", home) c.Assert(err, jc.ErrorIsNil) }) } diff --git a/home_test.go b/home_test.go index 05a4fc6..800f125 100644 --- a/home_test.go +++ b/home_test.go @@ -7,8 +7,8 @@ import ( "io/ioutil" "path/filepath" "runtime" + "os" - "github.com/juju/utils/v4" gc "gopkg.in/check.v1" "github.com/juju/testing" @@ -30,7 +30,7 @@ func (s *fakeHomeSuite) SetUpSuite(c *gc.C) { func (s *fakeHomeSuite) SetUpTest(c *gc.C) { s.IsolationSuite.SetUpTest(c) - err := utils.SetHome("/tmp/tests") + err := os.Setenv("HOME", "/tmp/tests") c.Assert(err, jc.ErrorIsNil) } @@ -42,16 +42,16 @@ func (s *fakeHomeSuite) TearDownSuite(c *gc.C) { func (s *fakeHomeSuite) TestHomeCreated(c *gc.C) { // A fake home is created and set. s.fakeHomeSuite.SetUpTest(c) - home := utils.Home() + home := os.Getenv("HOME") c.Assert(home, gc.Not(gc.Equals), "/tmp/tests") c.Assert(home, jc.IsDirectory) s.fakeHomeSuite.TearDownTest(c) // The original home has been restored. switch runtime.GOOS { case "windows": - c.Assert(utils.Home(), jc.SamePath, "C:/tmp/tests") + c.Assert(os.Getenv("HOME"), jc.SamePath, "C:/tmp/tests") default: - c.Assert(utils.Home(), jc.SamePath, "/tmp/tests") + c.Assert(os.Getenv("HOME"), jc.SamePath, "/tmp/tests") } } @@ -86,7 +86,7 @@ func (s *makeFakeHomeSuite) SetUpTest(c *gc.C) { func (s *makeFakeHomeSuite) TestAddFiles(c *gc.C) { // Files are correctly added to the fake home. - expectedPath := filepath.Join(utils.Home(), "testfile-name") + expectedPath := filepath.Join(os.Getenv("HOME"), "testfile-name") contents, err := ioutil.ReadFile(expectedPath) c.Assert(err, gc.IsNil) c.Assert(string(contents), gc.Equals, "testfile-data")