1
// Copyright 2015 Canonical Ltd.
2
// Licensed under the AGPLv3, see LICENCE file for details.
7
"github.com/juju/errors"
8
"github.com/juju/testing"
9
jc "github.com/juju/testing/checkers"
10
gc "gopkg.in/check.v1"
11
"gopkg.in/juju/names.v2"
13
"github.com/juju/juju/payload"
14
"github.com/juju/juju/payload/api"
15
"github.com/juju/juju/payload/api/client"
18
type publicSuite struct {
19
testing.IsolationSuite
26
var _ = gc.Suite(&publicSuite{})
28
func (s *publicSuite) SetUpTest(c *gc.C) {
29
s.IsolationSuite.SetUpTest(c)
31
s.stub = &testing.Stub{}
32
s.facade = &stubFacade{stub: s.stub}
33
s.payload = api.Payload{
37
Status: payload.StateRunning,
39
Unit: names.NewUnitTag("a-application/0").String(),
40
Machine: names.NewMachineTag("1").String(),
44
func (s *publicSuite) TestListOkay(c *gc.C) {
45
s.facade.FacadeCallFn = func(_ string, _, response interface{}) error {
46
typedResponse, ok := response.(*api.EnvListResults)
47
c.Assert(ok, gc.Equals, true)
48
typedResponse.Results = append(typedResponse.Results, s.payload)
52
pclient := client.NewPublicClient(s.facade)
54
payloads, err := pclient.ListFull("a-tag", "a-application/0")
55
c.Assert(err, jc.ErrorIsNil)
57
expected, _ := api.API2Payload(s.payload)
58
c.Check(payloads, jc.DeepEquals, []payload.FullPayloadInfo{
63
func (s *publicSuite) TestListAPI(c *gc.C) {
64
pclient := client.NewPublicClient(s.facade)
66
_, err := pclient.ListFull("a-tag")
67
c.Assert(err, jc.ErrorIsNil)
69
s.stub.CheckCalls(c, []testing.StubCall{{
70
FuncName: "FacadeCall",
74
Patterns: []string{"a-tag"},
83
type stubFacade struct {
85
FacadeCallFn func(name string, params, response interface{}) error
88
func (s *stubFacade) FacadeCall(request string, params, response interface{}) error {
89
s.stub.AddCall("FacadeCall", request, params, response)
90
if err := s.stub.NextErr(); err != nil {
91
return errors.Trace(err)
94
if s.FacadeCallFn != nil {
95
return s.FacadeCallFn(request, params, response)
100
func (s *stubFacade) Close() error {
101
s.stub.AddCall("Close")
102
if err := s.stub.NextErr(); err != nil {
103
return errors.Trace(err)