func (s *MainSuite) TestNoWarn1xWith2xData(c *gc.C) { // patch out lookpath to always return a nil error (and thus indicates success). s.PatchValue(&execLookPath, func(s string) (string, error) { c.Assert(s, gc.Equals, "juju-1") return "we ignore this anyway", nil }) // there should be a 2x home directory already created by the test setup. // create a fake old juju home. oldhome := osenv.OldJujuHomeDir() err := os.MkdirAll(oldhome, 0700) c.Assert(err, jc.ErrorIsNil) err = ioutil.WriteFile(filepath.Join(oldhome, "environments.yaml"), []byte("boo!"), 0600) c.Assert(err, jc.ErrorIsNil) // dump stderr to a file so we can examine it without any wacky re-running // of the executable (since we need to mock things out.) stderr, err := os.OpenFile(filepath.Join(oldhome, "stderr"), os.O_RDWR|os.O_CREATE, 0600) c.Assert(err, jc.ErrorIsNil) defer stderr.Close() // dump stdout to a file so it doesn't spam the test output. stdout, err := os.OpenFile(filepath.Join(oldhome, "stdout"), os.O_RDWR|os.O_CREATE, 0600) c.Assert(err, jc.ErrorIsNil) runMain(stderr, stdout, []string{"juju", "version"}) _, err = stderr.Seek(0, 0) c.Assert(err, jc.ErrorIsNil) output, err := ioutil.ReadAll(stderr) c.Assert(err, jc.ErrorIsNil) c.Assert(string(output), gc.Equals, "") }
func makeValidOldHome(c *gc.C) { oldhome := osenv.OldJujuHomeDir() err := os.MkdirAll(oldhome, 0700) c.Assert(err, jc.ErrorIsNil) err = ioutil.WriteFile(filepath.Join(oldhome, "environments.yaml"), []byte("boo!"), 0600) c.Assert(err, jc.ErrorIsNil) }
func (s *MainSuite) TestFirstRun2xFrom1x(c *gc.C) { // patch out lookpath to always return a nil error (and thus indicates success). s.PatchValue(&execLookPath, func(s string) (string, error) { c.Assert(s, gc.Equals, "juju-1") return "we ignore this anyway", nil }) // patch out the exec.Command used to run juju-1 so that it runs our test helper instead. s.PatchValue(&execCommand, func(command string, args ...string) *exec.Cmd { cs := []string{"-test.run=TestFirstRun2xFrom1xHelper", "--", command} cs = append(cs, args...) cmd := exec.Command(os.Args[0], cs...) cmd.Env = []string{"JUJU_WANT_HELPER_PROCESS=1"} return cmd }) // remove the new juju-home and create a fake old juju home. err := os.Remove(osenv.JujuXDGDataHome()) c.Assert(err, jc.ErrorIsNil) oldhome := osenv.OldJujuHomeDir() err = os.MkdirAll(oldhome, 0700) c.Assert(err, jc.ErrorIsNil) err = ioutil.WriteFile(filepath.Join(oldhome, "environments.yaml"), []byte("boo!"), 0600) c.Assert(err, jc.ErrorIsNil) // dump stderr to a file so we can examine it without any wacky re-running // of the executable (since we need to mock things out.) stderr, err := os.OpenFile(filepath.Join(oldhome, "stderr"), os.O_RDWR|os.O_CREATE, 0600) c.Assert(err, jc.ErrorIsNil) defer stderr.Close() // dump stdout to a file so it doesn't spam the test output. stdout, err := os.OpenFile(filepath.Join(oldhome, "stdout"), os.O_RDWR|os.O_CREATE, 0600) c.Assert(err, jc.ErrorIsNil) rc := runMain(stderr, stdout, []string{"juju", "version"}) c.Check(rc, gc.Equals, 0) _, err = stderr.Seek(0, 0) c.Assert(err, jc.ErrorIsNil) output, err := ioutil.ReadAll(stderr) c.Assert(err, jc.ErrorIsNil) c.Check(err, jc.ErrorIsNil) c.Check(string(output), gc.Equals, fmt.Sprintf(` Welcome to Juju %s. If you meant to use Juju 1.25.0 you can continue using it with the command juju-1 e.g. 'juju-1 switch'. See https://jujucharms.com/docs/stable/introducing-2 for more details. `[1:], jujuversion.Current)) }