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