github.com/mwhudson/juju@v0.0.0-20160512215208-90ff01f3497f/cmd/juju/controller/package_test.go (about)

     1  // Copyright 2015 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package controller_test
     5  
     6  import (
     7  	"testing"
     8  
     9  	jc "github.com/juju/testing/checkers"
    10  	gc "gopkg.in/check.v1"
    11  
    12  	"github.com/juju/juju/cmd/modelcmd"
    13  	"github.com/juju/juju/jujuclient"
    14  	"github.com/juju/juju/jujuclient/jujuclienttesting"
    15  	coretesting "github.com/juju/juju/testing"
    16  )
    17  
    18  func TestPackage(t *testing.T) {
    19  	gc.TestingT(t)
    20  }
    21  
    22  type baseControllerSuite struct {
    23  	coretesting.FakeJujuXDGDataHomeSuite
    24  	store                                     jujuclient.ClientStore
    25  	controllersYaml, modelsYaml, accountsYaml string
    26  	expectedOutput, expectedErr               string
    27  }
    28  
    29  func (s *baseControllerSuite) SetUpTest(c *gc.C) {
    30  	s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
    31  	s.controllersYaml = testControllersYaml
    32  	s.modelsYaml = testModelsYaml
    33  	s.accountsYaml = testAccountsYaml
    34  	s.store = nil
    35  
    36  	err := modelcmd.WriteCurrentController("local.mallards")
    37  	c.Assert(err, jc.ErrorIsNil)
    38  }
    39  
    40  func (s *baseControllerSuite) createTestClientStore(c *gc.C) *jujuclienttesting.MemStore {
    41  	controllers, err := jujuclient.ParseControllers([]byte(s.controllersYaml))
    42  	c.Assert(err, jc.ErrorIsNil)
    43  
    44  	models, err := jujuclient.ParseModels([]byte(s.modelsYaml))
    45  	c.Assert(err, jc.ErrorIsNil)
    46  
    47  	accounts, err := jujuclient.ParseAccounts([]byte(s.accountsYaml))
    48  	c.Assert(err, jc.ErrorIsNil)
    49  
    50  	store := jujuclienttesting.NewMemStore()
    51  	store.Controllers = controllers
    52  	store.Models = models
    53  	store.Accounts = accounts
    54  	s.store = store
    55  	return store
    56  }
    57  
    58  const testControllersYaml = `
    59  controllers:
    60    local.aws-test:
    61      uuid: this-is-the-aws-test-uuid
    62      api-endpoints: [this-is-aws-test-of-many-api-endpoints]
    63      ca-cert: this-is-aws-test-ca-cert
    64    local.mallards:
    65      uuid: this-is-another-uuid
    66      api-endpoints: [this-is-another-of-many-api-endpoints, this-is-one-more-of-many-api-endpoints]
    67      ca-cert: this-is-another-ca-cert
    68    local.mark-test-prodstack:
    69      uuid: this-is-a-uuid
    70      api-endpoints: [this-is-one-of-many-api-endpoints]
    71      ca-cert: this-is-a-ca-cert
    72  `
    73  
    74  const testModelsYaml = `
    75  controllers:
    76    local.aws-test:
    77      accounts:
    78        admin@local:
    79          models:
    80            admin:
    81              uuid: ghi
    82          current-model: admin
    83    local.mallards:
    84      accounts:
    85        admin@local:
    86          models:
    87            admin:
    88              uuid: abc
    89            my-model:
    90              uuid: def
    91          current-model: my-model
    92  `
    93  
    94  const testAccountsYaml = `
    95  controllers:
    96    local.aws-test:
    97      accounts:
    98        admin@local:
    99          user: admin@local
   100          password: hun+er2
   101    local.mark-test-prodstack:
   102      accounts:
   103        admin@local:
   104          user: admin@local
   105          password: hunter2
   106    local.mallards:
   107      accounts:
   108        admin@local:
   109          user: admin@local
   110          password: hunter2
   111        bob@local:
   112          user: bob@local
   113          password: huntert00
   114        bob@remote:
   115          user: bob@remote
   116      current-account: admin@local
   117  `