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