Пример #1
0
func (s *clientSuite) SetUpTest(c *gc.C) {
	s.httpClient = &mockHttpClient{}

	client, err := api.NewClient(api.HTTPClient(s.httpClient))
	c.Assert(err, jc.ErrorIsNil)
	s.client = client

}
Пример #2
0
func (s *clientSuite) TestBaseURL(c *gc.C) {
	client, err := api.NewClient(api.HTTPClient(s.httpClient), api.BaseURL("https://example.com"))
	c.Assert(err, jc.ErrorIsNil)

	s.httpClient.status = http.StatusNotFound
	_, err = client.GetAssociatedPlans("bob/uptime")
	c.Assert(err, gc.ErrorMatches, `failed to retrieve associated plans: received http response:  - code "Not Found"`)
	s.httpClient.CheckCall(c, 0, "Do", "https://example.com/charm?charm-url=bob%2Fuptime")
	s.httpClient.ResetCalls()

	m, err := macaroon.New(nil, "", "")
	c.Assert(err, jc.ErrorIsNil)
	data, err := json.Marshal(m)
	c.Assert(err, jc.ErrorIsNil)

	s.httpClient.status = http.StatusOK
	s.httpClient.body = data
	_, err = client.Authorize(utils.MustNewUUID().String(), "cs:trusty/test-charm-0", "test-charm", utils.MustNewUUID().String(), nil)
	c.Assert(err, jc.ErrorIsNil)
	s.httpClient.CheckCall(c, 0, "DoWithBody", "https://example.com/plan/authorize")
}
Пример #3
0
	"gopkg.in/yaml.v2"
	"launchpad.net/gnuflag"

	api "github.com/juju/romulus/api/plan"
	rcmd "github.com/juju/romulus/cmd"
	wireformat "github.com/juju/romulus/wireformat/plan"
)

// apiClient defines the interface of the plan api client need by this command.
type apiClient interface {
	// GetAssociatedPlans returns the plans associated with the charm.
	GetAssociatedPlans(charmURL string) ([]wireformat.Plan, error)
}

var newClient = func(client *httpbakery.Client) (apiClient, error) {
	return api.NewClient(api.HTTPClient(client))
}

const listPlansDoc = `
List plans available for the specified charm.

Examples:
    juju plans cs:webapp
`

// ListPlansCommand retrieves plans that are available for the specified charm
type ListPlansCommand struct {
	modelcmd.JujuCommandBase

	out      cmd.Output
	CharmURL string