github.com/juju/juju@v0.0.0-20240430160146-1752b71fcf00/api/agent/uniter/cloud_native_test.go (about)

     1  // Copyright 2018 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package uniter_test
     5  
     6  import (
     7  	"github.com/juju/names/v5"
     8  	jc "github.com/juju/testing/checkers"
     9  	gc "gopkg.in/check.v1"
    10  
    11  	"github.com/juju/juju/api/agent/uniter"
    12  	"github.com/juju/juju/api/base/testing"
    13  	"github.com/juju/juju/rpc/params"
    14  	coretesting "github.com/juju/juju/testing"
    15  )
    16  
    17  type cloudNativeUniterSuite struct {
    18  	coretesting.BaseSuite
    19  }
    20  
    21  var _ = gc.Suite(&cloudNativeUniterSuite{})
    22  
    23  func (s *cloudNativeUniterSuite) TestCloudSpec(c *gc.C) {
    24  	apiCaller := testing.APICallerFunc(func(objType string, version int, id, request string, arg, result interface{}) error {
    25  		c.Assert(objType, gc.Equals, "Uniter")
    26  		c.Assert(request, gc.Equals, "CloudSpec")
    27  		c.Assert(arg, gc.IsNil)
    28  		c.Assert(result, gc.FitsTypeOf, &params.CloudSpecResult{})
    29  		*(result.(*params.CloudSpecResult)) = params.CloudSpecResult{
    30  			Result: &params.CloudSpec{
    31  				Name: "dummy",
    32  				Credential: &params.CloudCredential{
    33  					Attributes: map[string]string{
    34  						"username": "dummy",
    35  						"password": "secret",
    36  					},
    37  				},
    38  			},
    39  		}
    40  		return nil
    41  	})
    42  	client := uniter.NewState(apiCaller, names.NewUnitTag("wordpress/0"))
    43  
    44  	result, err := client.CloudSpec()
    45  	c.Assert(err, jc.ErrorIsNil)
    46  	c.Assert(result.Name, gc.Equals, "dummy")
    47  	c.Assert(result.Credential.Attributes, gc.DeepEquals, map[string]string{
    48  		"username": "dummy",
    49  		"password": "secret",
    50  	})
    51  }