github.com/axw/juju@v0.0.0-20161005053422-4bd6544d08d4/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/jujuclient"
    13  	"github.com/juju/juju/jujuclient/jujuclienttesting"
    14  	coretesting "github.com/juju/juju/testing"
    15  )
    16  
    17  func TestPackage(t *testing.T) {
    18  	gc.TestingT(t)
    19  }
    20  
    21  type baseControllerSuite struct {
    22  	coretesting.FakeJujuXDGDataHomeSuite
    23  	store                                     jujuclient.ClientStore
    24  	controllersYaml, modelsYaml, accountsYaml string
    25  	expectedOutput, expectedErr               string
    26  }
    27  
    28  func (s *baseControllerSuite) SetUpTest(c *gc.C) {
    29  	s.FakeJujuXDGDataHomeSuite.SetUpTest(c)
    30  	s.controllersYaml = testControllersYaml
    31  	s.modelsYaml = testModelsYaml
    32  	s.accountsYaml = testAccountsYaml
    33  	s.store = nil
    34  }
    35  
    36  func (s *baseControllerSuite) createTestClientStore(c *gc.C) *jujuclienttesting.MemStore {
    37  	controllers, err := jujuclient.ParseControllers([]byte(s.controllersYaml))
    38  	c.Assert(err, jc.ErrorIsNil)
    39  
    40  	models, err := jujuclient.ParseModels([]byte(s.modelsYaml))
    41  	c.Assert(err, jc.ErrorIsNil)
    42  
    43  	accounts, err := jujuclient.ParseAccounts([]byte(s.accountsYaml))
    44  	c.Assert(err, jc.ErrorIsNil)
    45  
    46  	store := jujuclienttesting.NewMemStore()
    47  	store.Controllers = controllers.Controllers
    48  	store.CurrentControllerName = controllers.CurrentController
    49  	store.Models = models
    50  	store.Accounts = accounts
    51  	s.store = store
    52  	return store
    53  }
    54  
    55  const testControllersYaml = `
    56  controllers:
    57    aws-test:
    58      uuid: this-is-the-aws-test-uuid
    59      api-endpoints: [this-is-aws-test-of-many-api-endpoints]
    60      ca-cert: this-is-aws-test-ca-cert
    61      cloud: aws
    62      region: us-east-1
    63      model-count: 2
    64      machine-count: 5
    65      agent-version: 2.0.1
    66    mallards:
    67      uuid: this-is-another-uuid
    68      api-endpoints: [this-is-another-of-many-api-endpoints, this-is-one-more-of-many-api-endpoints]
    69      ca-cert: this-is-another-ca-cert
    70      cloud: mallards
    71      region: mallards1
    72    mark-test-prodstack:
    73      uuid: this-is-a-uuid
    74      api-endpoints: [this-is-one-of-many-api-endpoints]
    75      ca-cert: this-is-a-ca-cert
    76      cloud: prodstack
    77  current-controller: mallards
    78  `
    79  
    80  const testModelsYaml = `
    81  controllers:
    82    aws-test:
    83      models:
    84        controller:
    85          uuid: ghi
    86      current-model: controller
    87    mallards:
    88      models:
    89        controller:
    90          uuid: abc
    91        my-model:
    92          uuid: def
    93      current-model: my-model
    94  `
    95  
    96  const testAccountsYaml = `
    97  controllers:
    98    aws-test:
    99      user: admin@local
   100      password: hun+er2
   101    mark-test-prodstack:
   102      user: admin@local
   103      password: hunter2
   104    mallards:
   105      user: admin@local
   106      password: hunter2
   107      last-known-access: superuser
   108  `