コード例 #1
0
ファイル: apiconn_test.go プロジェクト: jameinel/core
func (s *APIEndpointForEnvSuite) TestAPIEndpointRefresh(c *gc.C) {
	defer coretesting.MakeEmptyFakeHome(c).Restore()
	store := newConfigStore("env-name", dummyStoreInfo)
	called := 0
	expectState := &mockAPIState{
		apiHostPorts: [][]instance.HostPort{
			instance.AddressesWithPort([]instance.Address{instance.NewAddress("0.1.2.3", instance.NetworkUnknown)}, 1234),
		},
	}
	apiOpen := func(apiInfo *api.Info, opts api.DialOpts) (juju.APIState, error) {
		c.Check(apiInfo.Tag, gc.Equals, "user-foo")
		c.Check(string(apiInfo.CACert), gc.Equals, "certificated")
		c.Check(apiInfo.Password, gc.Equals, "foopass")
		c.Check(opts, gc.DeepEquals, api.DefaultDialOpts())
		called++
		return expectState, nil
	}
	endpoint, err := juju.APIEndpointInStore("env-name", false, store, apiOpen)
	c.Assert(err, gc.IsNil)
	c.Assert(called, gc.Equals, 0)
	c.Check(endpoint.Addresses, gc.DeepEquals, []string{"foo.invalid"})
	// However, if we ask to refresh them, we'll connect to the API and get
	// the freshest set
	endpoint, err = juju.APIEndpointInStore("env-name", true, store, apiOpen)
	c.Assert(err, gc.IsNil)
	c.Check(called, gc.Equals, 1)
	// This refresh now gives us the values return by APIHostPorts
	c.Check(endpoint.Addresses, gc.DeepEquals, []string{"0.1.2.3:1234"})
}
コード例 #2
0
ファイル: apiconn_test.go プロジェクト: jameinel/core
func (s *APIEndpointForEnvSuite) TestAPIEndpointNotMachineLocal(c *gc.C) {
	defer coretesting.MakeEmptyFakeHome(c).Restore()
	store := newConfigStore("env-name", dummyStoreInfo)
	called := 0
	hostPorts := [][]instance.HostPort{
		instance.AddressesWithPort([]instance.Address{
			instance.NewAddress("1.0.0.1", instance.NetworkPublic),
			instance.NewAddress("192.0.0.1", instance.NetworkCloudLocal),
			instance.NewAddress("127.0.0.1", instance.NetworkMachineLocal),
			instance.NewAddress("localhost", instance.NetworkMachineLocal),
		}, 1234),
		instance.AddressesWithPort([]instance.Address{
			instance.NewAddress("1.0.0.2", instance.NetworkUnknown),
			instance.NewAddress("2002:0:0:0:0:0:100:2", instance.NetworkUnknown),
			instance.NewAddress("::1", instance.NetworkMachineLocal),
			instance.NewAddress("127.0.0.1", instance.NetworkMachineLocal),
			instance.NewAddress("localhost", instance.NetworkMachineLocal),
		}, 1235),
	}

	expectState := &mockAPIState{apiHostPorts: hostPorts}
	apiOpen := func(_ *api.Info, _ api.DialOpts) (juju.APIState, error) {
		called++
		return expectState, nil
	}
	endpoint, err := juju.APIEndpointInStore("env-name", true, store, apiOpen)
	c.Assert(err, gc.IsNil)
	c.Check(called, gc.Equals, 1)
	c.Check(endpoint.Addresses, gc.DeepEquals, []string{
		"1.0.0.1:1234",
		"192.0.0.1:1234",
		"1.0.0.2:1235",
	})
}
コード例 #3
0
ファイル: environ_test.go プロジェクト: jameinel/core
func (s *TestingEnvironSuite) TestFakeHomeRestoresEnvironment(c *gc.C) {
	fake := testing.MakeEmptyFakeHome(c)
	fake.Restore()
	c.Assert(osenv.Home(), gc.Equals, "/home/eric")
	c.Assert(os.Getenv("JUJU_HOME"), gc.Equals, "/home/eric/juju")
	c.Assert(osenv.JujuHome(), gc.Equals, "/home/eric/juju")
}
コード例 #4
0
ファイル: config_test.go プロジェクト: jameinel/core
func (*ConfigSuite) TestConfigNoCertFiles(c *gc.C) {
	h := testing.MakeEmptyFakeHome(c)
	defer h.Restore()
	for i, test := range noCertFilesTests {
		c.Logf("test %d. %s", i, test.about)
		test.check(c, h)
	}
}
コード例 #5
0
ファイル: clientkeys_test.go プロジェクト: jameinel/core
func (s *ClientKeysSuite) SetUpTest(c *gc.C) {
	s.LoggingSuite.SetUpTest(c)
	fakeHome := testing.MakeEmptyFakeHome(c)
	s.AddCleanup(func(*gc.C) { fakeHome.Restore() })
	s.AddCleanup(func(*gc.C) { ssh.ClearClientKeys() })
	generateKeyRestorer := overrideGenerateKey(c)
	s.AddCleanup(func(*gc.C) { generateKeyRestorer.Restore() })
}
コード例 #6
0
ファイル: apiconn_test.go プロジェクト: jameinel/core
func (s *NewAPIClientSuite) TestWithInfoError(c *gc.C) {
	defer coretesting.MakeEmptyFakeHome(c).Restore()
	expectErr := fmt.Errorf("an error")
	store := newConfigStoreWithError(expectErr)
	client, err := juju.NewAPIFromStore("noconfig", store, panicAPIOpen)
	c.Assert(err, gc.Equals, expectErr)
	c.Assert(client, gc.IsNil)
}
コード例 #7
0
ファイル: config_test.go プロジェクト: jameinel/core
func (s *ConfigSuite) SetUpTest(c *gc.C) {
	s.LoggingSuite.SetUpTest(c)
	s.oldJujuHome = testing.MakeEmptyFakeHome(c)
	s.savedVars = make(map[string]string)
	for v, val := range envVars {
		s.savedVars[v] = os.Getenv(v)
		os.Setenv(v, val)
	}
}
コード例 #8
0
ファイル: filevar_test.go プロジェクト: jameinel/core
func (s *FileVarSuite) TestTildeFileVar(c *gc.C) {
	defer testing.MakeEmptyFakeHome(c).Restore()
	path := filepath.Join(osenv.Home(), "config.yaml")
	err := ioutil.WriteFile(path, []byte("abc"), 0644)
	c.Assert(err, gc.IsNil)

	var config cmd.FileVar
	config.Set("~/config.yaml")
	file, err := config.Read(s.ctx)
	c.Assert(err, gc.IsNil)
	c.Assert(string(file), gc.Equals, "abc")
}
コード例 #9
0
ファイル: apiconn_test.go プロジェクト: jameinel/core
func (s *NewAPIClientSuite) TestWithInfoNoAddresses(c *gc.C) {
	defer coretesting.MakeEmptyFakeHome(c).Restore()
	store := newConfigStore("noconfig", &environInfo{
		endpoint: configstore.APIEndpoint{
			Addresses: []string{},
			CACert:    "certificated",
		},
	})
	st, err := juju.NewAPIFromStore("noconfig", store, panicAPIOpen)
	c.Assert(err, gc.ErrorMatches, `environment "noconfig" not found`)
	c.Assert(st, gc.IsNil)
}
コード例 #10
0
ファイル: init_test.go プロジェクト: jameinel/core
// The boilerplate is sent to stdout with --show, and the environments.yaml
// is not created.
func (*InitSuite) TestBoilerPlatePrinted(c *gc.C) {
	defer testing.MakeEmptyFakeHome(c).Restore()
	ctx := testing.Context(c)
	code := cmd.Main(&InitCommand{}, ctx, []string{"--show"})
	c.Check(code, gc.Equals, 0)
	outStr := ctx.Stdout.(*bytes.Buffer).String()
	strippedOut := strings.Replace(outStr, "\n", "", -1)
	c.Check(strippedOut, gc.Matches, ".*# This is the Juju config file, which you can use.*")
	environpath := testing.HomePath(".juju", "environments.yaml")
	_, err := ioutil.ReadFile(environpath)
	c.Assert(err, gc.NotNil)
}
コード例 #11
0
ファイル: init_test.go プロジェクト: jameinel/core
// The environments.yaml is created by default if it
// does not already exist.
func (*InitSuite) TestBoilerPlateEnvironment(c *gc.C) {
	defer testing.MakeEmptyFakeHome(c).Restore()
	ctx := testing.Context(c)
	code := cmd.Main(&InitCommand{}, ctx, nil)
	c.Check(code, gc.Equals, 0)
	outStr := ctx.Stdout.(*bytes.Buffer).String()
	strippedOut := strings.Replace(outStr, "\n", "", -1)
	c.Check(strippedOut, gc.Matches, ".*A boilerplate environment configuration file has been written.*")
	environpath := testing.HomePath(".juju", "environments.yaml")
	data, err := ioutil.ReadFile(environpath)
	c.Assert(err, gc.IsNil)
	strippedData := strings.Replace(string(data), "\n", "", -1)
	c.Assert(strippedData, gc.Matches, ".*# This is the Juju config file, which you can use.*")
}
コード例 #12
0
ファイル: apiconn_test.go プロジェクト: jameinel/core
func (s *NewAPIClientSuite) TestWithInfoAPIOpenError(c *gc.C) {
	defer coretesting.MakeEmptyFakeHome(c).Restore()
	store := newConfigStore("noconfig", &environInfo{
		endpoint: configstore.APIEndpoint{
			Addresses: []string{"foo.invalid"},
		},
	})

	expectErr := fmt.Errorf("an error")
	apiOpen := func(apiInfo *api.Info, opts api.DialOpts) (juju.APIState, error) {
		return nil, expectErr
	}
	st, err := juju.NewAPIFromStore("noconfig", store, apiOpen)
	c.Assert(err, gc.Equals, expectErr)
	c.Assert(st, gc.IsNil)
}
コード例 #13
0
ファイル: config_test.go プロジェクト: jameinel/core
func (*suite) TestDefaultConfigFile(c *gc.C) {
	defer testing.MakeEmptyFakeHome(c).Restore()

	env := `
environments:
    only:
        type: dummy
        state-server: false
        authorized-keys: i-am-a-key
`
	outfile, err := environs.WriteEnvirons("", env)
	c.Assert(err, gc.IsNil)
	path := testing.HomePath(".juju", "environments.yaml")
	c.Assert(path, gc.Equals, outfile)

	envs, err := environs.ReadEnvirons("")
	c.Assert(err, gc.IsNil)
	cfg, err := envs.Config("")
	c.Assert(err, gc.IsNil)
	c.Assert(cfg.Name(), gc.Equals, "only")
}
コード例 #14
0
ファイル: apiconn_test.go プロジェクト: jameinel/core
func (s *NewAPIClientSuite) TestWithInfoOnly(c *gc.C) {
	defer coretesting.MakeEmptyFakeHome(c).Restore()
	store := newConfigStore("noconfig", dummyStoreInfo)

	called := 0
	expectState := &mockAPIState{
		apiHostPorts: [][]instance.HostPort{
			instance.AddressesWithPort([]instance.Address{instance.NewAddress("0.1.2.3", instance.NetworkUnknown)}, 1234),
		},
	}
	apiOpen := func(apiInfo *api.Info, opts api.DialOpts) (juju.APIState, error) {
		c.Check(apiInfo.Tag, gc.Equals, "user-foo")
		c.Check(string(apiInfo.CACert), gc.Equals, "certificated")
		c.Check(apiInfo.Password, gc.Equals, "foopass")
		c.Check(opts, gc.DeepEquals, api.DefaultDialOpts())
		called++
		return expectState, nil
	}

	// Give NewAPIFromStore a store interface that can report when the
	// config was written to, to check if the cache is updated.
	mockStore := &storageWithWriteNotify{store: store}
	st, err := juju.NewAPIFromStore("noconfig", mockStore, apiOpen)
	c.Assert(err, gc.IsNil)
	c.Assert(st, gc.Equals, expectState)
	c.Assert(called, gc.Equals, 1)
	c.Assert(mockStore.written, jc.IsTrue)
	info, err := store.ReadInfo("noconfig")
	c.Assert(err, gc.IsNil)
	c.Assert(info.APIEndpoint().Addresses, gc.DeepEquals, []string{"0.1.2.3:1234"})
	mockStore.written = false

	// If APIHostPorts haven't changed, then the store won't be updated.
	st, err = juju.NewAPIFromStore("noconfig", mockStore, apiOpen)
	c.Assert(err, gc.IsNil)
	c.Assert(st, gc.Equals, expectState)
	c.Assert(called, gc.Equals, 2)
	c.Assert(mockStore.written, jc.IsFalse)
}
コード例 #15
0
ファイル: metadataplugin_test.go プロジェクト: jameinel/core
func (s *MetadataSuite) SetUpTest(c *gc.C) {
	s.jujuHome = testing.MakeEmptyFakeHome(c)
}
コード例 #16
0
func (s *EnvironmentCommandSuite) SetUpTest(c *gc.C) {
	s.home = coretesting.MakeEmptyFakeHome(c)
}
コード例 #17
0
ファイル: urls_test.go プロジェクト: jameinel/core
func (s *URLsSuite) SetUpTest(c *gc.C) {
	s.home = testing.MakeEmptyFakeHome(c)
}
コード例 #18
0
ファイル: environ_test.go プロジェクト: jameinel/core
func (s *TestingEnvironSuite) TestFakeHomeReplacesEnvironment(c *gc.C) {
	_ = testing.MakeEmptyFakeHome(c)
	c.Assert(osenv.Home(), gc.Not(gc.Equals), "/home/eric")
	c.Assert(os.Getenv("JUJU_HOME"), gc.Equals, "")
	c.Assert(osenv.JujuHome(), gc.Not(gc.Equals), "/home/eric/juju")
}
コード例 #19
0
ファイル: authorizedkeys_test.go プロジェクト: jameinel/core
func (s *AuthorizedKeysSuite) SetUpTest(c *gc.C) {
	s.LoggingSuite.SetUpTest(c)
	s.jujuHome = coretesting.MakeEmptyFakeHome(c)
}
コード例 #20
0
ファイル: switch_test.go プロジェクト: jameinel/core
func (*SwitchSimpleSuite) TestNoEnvironment(c *gc.C) {
	defer testing.MakeEmptyFakeHome(c).Restore()
	_, err := testing.RunCommand(c, &SwitchCommand{}, nil)
	c.Assert(err, gc.ErrorMatches, "couldn't read the environment")
}
コード例 #21
0
ファイル: environ_test.go プロジェクト: jameinel/core
func (s *TestingEnvironSuite) TestFakeHomeSetsConfigJujuHome(c *gc.C) {
	_ = testing.MakeEmptyFakeHome(c)
	expected := filepath.Join(osenv.Home(), ".juju")
	c.Assert(osenv.JujuHome(), gc.Equals, expected)
}