1
// Copyright 2016 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
4
package stateenvirons_test
7
jc "github.com/juju/testing/checkers"
10
"github.com/juju/juju/cloud"
11
"github.com/juju/juju/environs"
12
"github.com/juju/juju/state/stateenvirons"
13
statetesting "github.com/juju/juju/state/testing"
14
"github.com/juju/juju/testing/factory"
17
type environSuite struct {
18
statetesting.StateSuite
21
var _ = gc.Suite(&environSuite{})
23
func (s *environSuite) TestGetNewEnvironFunc(c *gc.C) {
25
var callArgs environs.OpenParams
26
newEnviron := func(args environs.OpenParams) (environs.Environ, error) {
31
stateenvirons.GetNewEnvironFunc(newEnviron)(s.State)
32
c.Assert(calls, gc.Equals, 1)
34
cfg, err := s.State.ModelConfig()
35
c.Assert(err, jc.ErrorIsNil)
36
c.Assert(callArgs.Config, jc.DeepEquals, cfg)
39
func (s *environSuite) TestCloudSpec(c *gc.C) {
40
owner := s.Factory.MakeUser(c, nil).UserTag()
41
emptyCredential := cloud.NewEmptyCredential()
42
err := s.State.UpdateCloudCredentials(owner, "dummy", map[string]cloud.Credential{
43
"empty-credential": emptyCredential,
45
c.Assert(err, jc.ErrorIsNil)
47
st := s.Factory.MakeModel(c, &factory.ModelParams{
50
CloudCredential: "empty-credential",
55
emptyCredential.Label = "empty-credential"
56
cloudSpec, err := stateenvirons.EnvironConfigGetter{st}.CloudSpec(st.ModelTag())
57
c.Assert(err, jc.ErrorIsNil)
58
c.Assert(cloudSpec, jc.DeepEquals, environs.CloudSpec{
61
Credential: &emptyCredential,