github.com/niedbalski/juju@v0.0.0-20190215020005-8ff100488e47/environs/simplestreams/testing/stub.go (about) 1 // Copyright 2016 Canonical Ltd. 2 // Licensed under the AGPLv3, see LICENCE file for details. 3 4 package testing 5 6 import ( 7 "io" 8 9 "github.com/juju/testing" 10 ) 11 12 type StubDataSource struct { 13 testing.Stub 14 15 DescriptionFunc func() string 16 FetchFunc func(path string) (io.ReadCloser, string, error) 17 URLFunc func(path string) (string, error) 18 PublicSigningKeyFunc func() string 19 SetAllowRetryFunc func(allow bool) 20 PriorityFunc func() int 21 RequireSignedFunc func() bool 22 } 23 24 func NewStubDataSource() *StubDataSource { 25 result := &StubDataSource{ 26 DescriptionFunc: func() string { 27 return "" 28 }, 29 PublicSigningKeyFunc: func() string { 30 return "" 31 }, 32 SetAllowRetryFunc: func(allow bool) {}, 33 PriorityFunc: func() int { 34 return 0 35 }, 36 RequireSignedFunc: func() bool { 37 return false 38 }, 39 } 40 result.FetchFunc = func(path string) (io.ReadCloser, string, error) { 41 return nil, "", result.Stub.NextErr() 42 } 43 result.URLFunc = func(path string) (string, error) { 44 return "", result.Stub.NextErr() 45 } 46 return result 47 } 48 49 // Description implements simplestreams.DataSource. 50 func (s *StubDataSource) Description() string { 51 s.MethodCall(s, "Description") 52 return s.DescriptionFunc() 53 } 54 55 // Description implements simplestreams.DataSource. 56 func (s *StubDataSource) Fetch(path string) (io.ReadCloser, string, error) { 57 s.MethodCall(s, "Fetch", path) 58 return s.FetchFunc(path) 59 } 60 61 // Description implements simplestreams.DataSource. 62 func (s *StubDataSource) URL(path string) (string, error) { 63 s.MethodCall(s, "URL", path) 64 return s.URLFunc(path) 65 } 66 67 // Description implements simplestreams.DataSource. 68 func (s *StubDataSource) PublicSigningKey() string { 69 s.MethodCall(s, "PublicSigningKey") 70 return s.PublicSigningKeyFunc() 71 } 72 73 // Description implements simplestreams.DataSource. 74 func (s *StubDataSource) SetAllowRetry(allow bool) { 75 s.MethodCall(s, "SetAllowRetry", allow) 76 s.SetAllowRetryFunc(allow) 77 } 78 79 // Description implements simplestreams.DataSource. 80 func (s *StubDataSource) Priority() int { 81 s.MethodCall(s, "Priority") 82 return s.PriorityFunc() 83 } 84 85 // Description implements simplestreams.DataSource. 86 func (s *StubDataSource) RequireSigned() bool { 87 s.MethodCall(s, "RequireSigned") 88 return s.RequireSignedFunc() 89 }