-
Notifications
You must be signed in to change notification settings - Fork 238
/
get_mock.go
57 lines (45 loc) · 1.06 KB
/
get_mock.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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package getter
import (
"net/url"
)
// MockGetter is an implementation of Getter that can be used for tests.
type MockGetter struct {
getter
// Proxy, if set, will be called after recording the calls below.
// If it isn't set, then the *Err values will be returned.
Proxy Getter
GetCalled bool
GetDst string
GetURL *url.URL
GetErr error
GetFileCalled bool
GetFileDst string
GetFileURL *url.URL
GetFileErr error
}
func (g *MockGetter) Get(dst string, u *url.URL) error {
g.GetCalled = true
g.GetDst = dst
g.GetURL = u
if g.Proxy != nil {
return g.Proxy.Get(dst, u)
}
return g.GetErr
}
func (g *MockGetter) GetFile(dst string, u *url.URL) error {
g.GetFileCalled = true
g.GetFileDst = dst
g.GetFileURL = u
if g.Proxy != nil {
return g.Proxy.GetFile(dst, u)
}
return g.GetFileErr
}
func (g *MockGetter) ClientMode(u *url.URL) (ClientMode, error) {
if l := len(u.Path); l > 0 && u.Path[l-1:] == "/" {
return ClientModeDir, nil
}
return ClientModeFile, nil
}