github.com/makyo/juju@v0.0.0-20160425123129-2608902037e9/resource/cmd/stub_test.go (about) 1 // Copyright 2015 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package cmd 5 6 import ( 7 "io" 8 9 "github.com/juju/cmd" 10 "github.com/juju/errors" 11 "github.com/juju/juju/charmstore" 12 "github.com/juju/testing" 13 charmresource "gopkg.in/juju/charm.v6-unstable/resource" 14 ) 15 16 type stubCharmStore struct { 17 stub *testing.Stub 18 19 ReturnListResources [][]charmresource.Resource 20 } 21 22 func (s *stubCharmStore) Connect(ctx *cmd.Context) (CharmResourceLister, error) { 23 s.stub.AddCall("Connect", ctx) 24 if err := s.stub.NextErr(); err != nil { 25 return nil, errors.Trace(err) 26 } 27 28 return s, nil 29 } 30 31 func (s *stubCharmStore) ListResources(charms []charmstore.CharmID) ([][]charmresource.Resource, error) { 32 s.stub.AddCall("ListResources", charms) 33 if err := s.stub.NextErr(); err != nil { 34 return nil, errors.Trace(err) 35 } 36 37 return s.ReturnListResources, nil 38 } 39 40 func (s *stubCharmStore) Close() error { 41 s.stub.AddCall("Close") 42 if err := s.stub.NextErr(); err != nil { 43 return errors.Trace(err) 44 } 45 46 return nil 47 } 48 49 type stubAPIClient struct { 50 stub *testing.Stub 51 } 52 53 func (s *stubAPIClient) Upload(service, name, filename string, resource io.ReadSeeker) error { 54 s.stub.AddCall("Upload", service, name, filename, resource) 55 if err := s.stub.NextErr(); err != nil { 56 return errors.Trace(err) 57 } 58 59 return nil 60 } 61 62 func (s *stubAPIClient) Close() error { 63 s.stub.AddCall("Close") 64 if err := s.stub.NextErr(); err != nil { 65 return errors.Trace(err) 66 } 67 68 return nil 69 } 70 71 type stubFile struct { 72 // No one actually tries to read from this during tests. 73 io.ReadSeeker 74 stub *testing.Stub 75 } 76 77 func (s *stubFile) Close() error { 78 s.stub.AddCall("FileClose") 79 return errors.Trace(s.stub.NextErr()) 80 }