diff options
Diffstat (limited to 'vendor/github.com/hashicorp/go-getter/get_mock.go')
-rw-r--r-- | vendor/github.com/hashicorp/go-getter/get_mock.go | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/vendor/github.com/hashicorp/go-getter/get_mock.go b/vendor/github.com/hashicorp/go-getter/get_mock.go new file mode 100644 index 0000000..882e694 --- /dev/null +++ b/vendor/github.com/hashicorp/go-getter/get_mock.go | |||
@@ -0,0 +1,52 @@ | |||
1 | package getter | ||
2 | |||
3 | import ( | ||
4 | "net/url" | ||
5 | ) | ||
6 | |||
7 | // MockGetter is an implementation of Getter that can be used for tests. | ||
8 | type MockGetter struct { | ||
9 | // Proxy, if set, will be called after recording the calls below. | ||
10 | // If it isn't set, then the *Err values will be returned. | ||
11 | Proxy Getter | ||
12 | |||
13 | GetCalled bool | ||
14 | GetDst string | ||
15 | GetURL *url.URL | ||
16 | GetErr error | ||
17 | |||
18 | GetFileCalled bool | ||
19 | GetFileDst string | ||
20 | GetFileURL *url.URL | ||
21 | GetFileErr error | ||
22 | } | ||
23 | |||
24 | func (g *MockGetter) Get(dst string, u *url.URL) error { | ||
25 | g.GetCalled = true | ||
26 | g.GetDst = dst | ||
27 | g.GetURL = u | ||
28 | |||
29 | if g.Proxy != nil { | ||
30 | return g.Proxy.Get(dst, u) | ||
31 | } | ||
32 | |||
33 | return g.GetErr | ||
34 | } | ||
35 | |||
36 | func (g *MockGetter) GetFile(dst string, u *url.URL) error { | ||
37 | g.GetFileCalled = true | ||
38 | g.GetFileDst = dst | ||
39 | g.GetFileURL = u | ||
40 | |||
41 | if g.Proxy != nil { | ||
42 | return g.Proxy.GetFile(dst, u) | ||
43 | } | ||
44 | return g.GetFileErr | ||
45 | } | ||
46 | |||
47 | func (g *MockGetter) ClientMode(u *url.URL) (ClientMode, error) { | ||
48 | if l := len(u.Path); l > 0 && u.Path[l-1:] == "/" { | ||
49 | return ClientModeDir, nil | ||
50 | } | ||
51 | return ClientModeFile, nil | ||
52 | } | ||