github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/payload/api/client/public_test.go (about) 1 package client_test 2 3 import ( 4 "github.com/juju/errors" 5 "github.com/juju/names" 6 "github.com/juju/testing" 7 jc "github.com/juju/testing/checkers" 8 gc "gopkg.in/check.v1" 9 10 "github.com/juju/juju/payload" 11 "github.com/juju/juju/payload/api" 12 "github.com/juju/juju/payload/api/client" 13 ) 14 15 type publicSuite struct { 16 testing.IsolationSuite 17 18 stub *testing.Stub 19 facade *stubFacade 20 payload api.Payload 21 } 22 23 var _ = gc.Suite(&publicSuite{}) 24 25 func (s *publicSuite) SetUpTest(c *gc.C) { 26 s.IsolationSuite.SetUpTest(c) 27 28 s.stub = &testing.Stub{} 29 s.facade = &stubFacade{stub: s.stub} 30 s.payload = api.Payload{ 31 Class: "spam", 32 Type: "docker", 33 ID: "idspam", 34 Status: payload.StateRunning, 35 Labels: nil, 36 Unit: names.NewUnitTag("a-service/0").String(), 37 Machine: names.NewMachineTag("1").String(), 38 } 39 } 40 41 func (s *publicSuite) TestListOkay(c *gc.C) { 42 s.facade.FacadeCallFn = func(_ string, _, response interface{}) error { 43 typedResponse, ok := response.(*api.EnvListResults) 44 c.Assert(ok, gc.Equals, true) 45 typedResponse.Results = append(typedResponse.Results, s.payload) 46 return nil 47 } 48 49 pclient := client.NewPublicClient(s.facade) 50 51 payloads, err := pclient.ListFull("a-tag", "a-service/0") 52 c.Assert(err, jc.ErrorIsNil) 53 54 expected, _ := api.API2Payload(s.payload) 55 c.Check(payloads, jc.DeepEquals, []payload.FullPayloadInfo{ 56 expected, 57 }) 58 } 59 60 func (s *publicSuite) TestListAPI(c *gc.C) { 61 pclient := client.NewPublicClient(s.facade) 62 63 _, err := pclient.ListFull("a-tag") 64 c.Assert(err, jc.ErrorIsNil) 65 66 s.stub.CheckCalls(c, []testing.StubCall{{ 67 FuncName: "FacadeCall", 68 Args: []interface{}{ 69 "List", 70 &api.EnvListArgs{ 71 Patterns: []string{"a-tag"}, 72 }, 73 &api.EnvListResults{ 74 Results: nil, 75 }, 76 }, 77 }}) 78 } 79 80 type stubFacade struct { 81 stub *testing.Stub 82 FacadeCallFn func(name string, params, response interface{}) error 83 } 84 85 func (s *stubFacade) FacadeCall(request string, params, response interface{}) error { 86 s.stub.AddCall("FacadeCall", request, params, response) 87 if err := s.stub.NextErr(); err != nil { 88 return errors.Trace(err) 89 } 90 91 if s.FacadeCallFn != nil { 92 return s.FacadeCallFn(request, params, response) 93 } 94 return nil 95 } 96 97 func (s *stubFacade) Close() error { 98 s.stub.AddCall("Close") 99 if err := s.stub.NextErr(); err != nil { 100 return errors.Trace(err) 101 } 102 103 return nil 104 }