github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/featuretests/api_cloud_test.go (about)

     1  // Copyright 2016 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package featuretests
     5  
     6  import (
     7  	jc "github.com/juju/testing/checkers"
     8  	gc "gopkg.in/check.v1"
     9  	"gopkg.in/juju/names.v2"
    10  
    11  	apicloud "github.com/juju/juju/api/cloud"
    12  	"github.com/juju/juju/apiserver/params"
    13  	"github.com/juju/juju/cloud"
    14  	"github.com/juju/juju/juju/testing"
    15  )
    16  
    17  // NOTE(axw) this suite only exists because nothing exercises
    18  // the cloud API enough to expose serialisation bugs such as
    19  // lp:1607557. If/when we have commands that would expose that
    20  // bug, we should drop this suite and write a new command-based
    21  // one.
    22  
    23  type CloudAPISuite struct {
    24  	testing.JujuConnSuite
    25  	client *apicloud.Client
    26  }
    27  
    28  func (s *CloudAPISuite) SetUpTest(c *gc.C) {
    29  	s.JujuConnSuite.SetUpTest(c)
    30  	s.client = apicloud.NewClient(s.OpenControllerAPI(c))
    31  }
    32  
    33  func (s *CloudAPISuite) TearDownTest(c *gc.C) {
    34  	s.client.Close()
    35  	s.JujuConnSuite.TearDownTest(c)
    36  }
    37  
    38  func (s *CloudAPISuite) TestCloudAPI(c *gc.C) {
    39  	result, err := s.client.Cloud(names.NewCloudTag("dummy"))
    40  	c.Assert(err, jc.ErrorIsNil)
    41  	c.Assert(result, jc.DeepEquals, cloud.Cloud{
    42  		Name:      "dummy",
    43  		Type:      "dummy",
    44  		AuthTypes: []cloud.AuthType{cloud.EmptyAuthType, cloud.UserPassAuthType},
    45  		Regions: []cloud.Region{
    46  			{
    47  				Name:             "dummy-region",
    48  				Endpoint:         "dummy-endpoint",
    49  				IdentityEndpoint: "dummy-identity-endpoint",
    50  				StorageEndpoint:  "dummy-storage-endpoint",
    51  			},
    52  		},
    53  		Endpoint:         "dummy-endpoint",
    54  		IdentityEndpoint: "dummy-identity-endpoint",
    55  		StorageEndpoint:  "dummy-storage-endpoint",
    56  	})
    57  }
    58  
    59  func (s *CloudAPISuite) TestCredentialsAPI(c *gc.C) {
    60  	tag := names.NewCloudCredentialTag("dummy/admin/default")
    61  	_, err := s.client.UpdateCredentialsCheckModels(tag, cloud.NewCredential(
    62  		cloud.UserPassAuthType,
    63  		map[string]string{"username": "fred", "password": "secret"},
    64  	))
    65  	c.Assert(err, jc.ErrorIsNil)
    66  	result, err := s.client.Credentials(tag)
    67  	c.Assert(err, jc.ErrorIsNil)
    68  	c.Assert(result, jc.DeepEquals, []params.CloudCredentialResult{
    69  		{Result: &params.CloudCredential{
    70  			AuthType:   "userpass",
    71  			Attributes: map[string]string{"username": "fred"},
    72  			Redacted:   []string{"password"},
    73  		}},
    74  	})
    75  }