github.com/mhilton/juju-juju@v0.0.0-20150901100907-a94dd2c73455/provider/gce/provider_test.go (about) 1 // Copyright 2014 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package gce_test 5 6 import ( 7 jc "github.com/juju/testing/checkers" 8 gc "gopkg.in/check.v1" 9 10 "github.com/juju/juju/environs" 11 envtesting "github.com/juju/juju/environs/testing" 12 "github.com/juju/juju/provider/gce" 13 ) 14 15 type providerSuite struct { 16 gce.BaseSuite 17 18 provider environs.EnvironProvider 19 } 20 21 var _ = gc.Suite(&providerSuite{}) 22 23 func (s *providerSuite) SetUpTest(c *gc.C) { 24 s.BaseSuite.SetUpTest(c) 25 26 var err error 27 s.provider, err = environs.Provider("gce") 28 c.Check(err, jc.ErrorIsNil) 29 } 30 31 func (s *providerSuite) TestRegistered(c *gc.C) { 32 c.Assert(s.provider, gc.Equals, gce.Provider) 33 } 34 35 func (s *providerSuite) TestOpen(c *gc.C) { 36 env, err := s.provider.Open(s.Config) 37 c.Check(err, jc.ErrorIsNil) 38 39 envConfig := env.Config() 40 c.Assert(envConfig.Name(), gc.Equals, "testenv") 41 } 42 43 func (s *providerSuite) TestPrepareForBootstrap(c *gc.C) { 44 env, err := s.provider.PrepareForBootstrap(envtesting.BootstrapContext(c), s.Config) 45 c.Check(err, jc.ErrorIsNil) 46 c.Check(env, gc.NotNil) 47 } 48 49 func (s *providerSuite) TestValidate(c *gc.C) { 50 validCfg, err := s.provider.Validate(s.Config, nil) 51 c.Check(err, jc.ErrorIsNil) 52 53 validAttrs := validCfg.AllAttrs() 54 c.Assert(s.Config.AllAttrs(), gc.DeepEquals, validAttrs) 55 } 56 57 func (s *providerSuite) TestSecretAttrs(c *gc.C) { 58 obtainedAttrs, err := s.provider.SecretAttrs(s.Config) 59 c.Check(err, jc.ErrorIsNil) 60 61 expectedAttrs := map[string]string{"private-key": gce.PrivateKey} 62 c.Assert(obtainedAttrs, gc.DeepEquals, expectedAttrs) 63 64 } 65 66 func (s *providerSuite) TestBoilerplateConfig(c *gc.C) { 67 // (wwitzel3) purposefully duplicate here so that this test will 68 // fail if someone updates gce/config.go without updating this test. 69 var boilerplateConfig = ` 70 gce: 71 type: gce 72 73 # Google Auth Info 74 # The GCE provider uses OAuth to authenticate. This requires that 75 # you set it up and get the relevant credentials. For more information 76 # see https://cloud.google.com/compute/docs/api/how-tos/authorization. 77 # The key information can be downloaded as a JSON file, or copied, from: 78 # https://console.developers.google.com/project/<projet>/apiui/credential 79 # Either set the path to the downloaded JSON file here: 80 auth-file: 81 82 # ...or set the individual fields for the credentials. Either way, all 83 # three of these are required and have specific meaning to GCE. 84 # private-key: 85 # client-email: 86 # client-id: 87 88 # Google instance info 89 # To provision instances and perform related operations, the provider 90 # will need to know which GCE project to use and into which region to 91 # provision. While the region has a default, the project ID is 92 # required. For information on the project ID, see 93 # https://cloud.google.com/compute/docs/projects and regarding regions 94 # see https://cloud.google.com/compute/docs/zones. 95 project-id: 96 # region: us-central1 97 98 # The GCE provider uses pre-built images when provisioning instances. 99 # You can customize the location in which to find them with the 100 # image-endpoint setting. The default value is the a location within 101 # GCE, so it will give you the best speed when bootstrapping or adding 102 # machines. For more information on the image cache see 103 # https://cloud-images.ubuntu.com/. 104 # image-endpoint: https://www.googleapis.com 105 `[1:] 106 c.Assert(s.provider.BoilerplateConfig(), gc.Equals, boilerplateConfig) 107 }