This repository has been archived by the owner on Nov 1, 2022. It is now read-only.
/
mock.go
89 lines (71 loc) · 3.51 KB
/
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
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
package mock
import (
"bytes"
"context"
"github.com/weaveworks/flux/cluster"
"github.com/weaveworks/flux/image"
"github.com/weaveworks/flux/manifests"
"github.com/weaveworks/flux/resource"
"github.com/weaveworks/flux/ssh"
)
// Doubles as a cluster.Cluster and cluster.Manifests implementation
type Mock struct {
AllWorkloadsFunc func(ctx context.Context, maybeNamespace string) ([]cluster.Workload, error)
SomeWorkloadsFunc func(ctx context.Context, ids []resource.ID) ([]cluster.Workload, error)
IsAllowedResourceFunc func(resource.ID) bool
PingFunc func() error
ExportFunc func(ctx context.Context) ([]byte, error)
SyncFunc func(cluster.SyncSet) error
PublicSSHKeyFunc func(regenerate bool) (ssh.PublicKey, error)
SetWorkloadContainerImageFunc func(def []byte, id resource.ID, container string, newImageID image.Ref) ([]byte, error)
LoadManifestsFunc func(base string, paths []string) (map[string]resource.Resource, error)
ParseManifestFunc func(def []byte, source string) (map[string]resource.Resource, error)
UpdateWorkloadPoliciesFunc func([]byte, resource.ID, resource.PolicyUpdate) ([]byte, error)
CreateManifestPatchFunc func(originalManifests, modifiedManifests []byte, originalSource, modifiedSource string) ([]byte, error)
ApplyManifestPatchFunc func(originalManifests, patch []byte, originalSource, patchSource string) ([]byte, error)
AppendManifestToBufferFunc func([]byte, *bytes.Buffer) error
}
var _ cluster.Cluster = &Mock{}
var _ manifests.Manifests = &Mock{}
func (m *Mock) AllWorkloads(ctx context.Context, maybeNamespace string) ([]cluster.Workload, error) {
return m.AllWorkloadsFunc(ctx, maybeNamespace)
}
func (m *Mock) SomeWorkloads(ctx context.Context, ids []resource.ID) ([]cluster.Workload, error) {
return m.SomeWorkloadsFunc(ctx, ids)
}
func (m *Mock) IsAllowedResource(id resource.ID) bool {
return m.IsAllowedResourceFunc(id)
}
func (m *Mock) Ping() error {
return m.PingFunc()
}
func (m *Mock) Export(ctx context.Context) ([]byte, error) {
return m.ExportFunc(ctx)
}
func (m *Mock) Sync(c cluster.SyncSet) error {
return m.SyncFunc(c)
}
func (m *Mock) PublicSSHKey(regenerate bool) (ssh.PublicKey, error) {
return m.PublicSSHKeyFunc(regenerate)
}
func (m *Mock) SetWorkloadContainerImage(def []byte, id resource.ID, container string, newImageID image.Ref) ([]byte, error) {
return m.SetWorkloadContainerImageFunc(def, id, container, newImageID)
}
func (m *Mock) LoadManifests(baseDir string, paths []string) (map[string]resource.Resource, error) {
return m.LoadManifestsFunc(baseDir, paths)
}
func (m *Mock) ParseManifest(def []byte, source string) (map[string]resource.Resource, error) {
return m.ParseManifestFunc(def, source)
}
func (m *Mock) UpdateWorkloadPolicies(def []byte, id resource.ID, p resource.PolicyUpdate) ([]byte, error) {
return m.UpdateWorkloadPoliciesFunc(def, id, p)
}
func (m *Mock) CreateManifestPatch(originalManifests, modifiedManifests []byte, originalSource, modifiedSource string) ([]byte, error) {
return m.CreateManifestPatchFunc(originalManifests, modifiedManifests, originalSource, modifiedSource)
}
func (m *Mock) ApplyManifestPatch(originalManifests, patch []byte, originalSource, patchSource string) ([]byte, error) {
return m.ApplyManifestPatch(originalManifests, patch, originalSource, patchSource)
}
func (m *Mock) AppendManifestToBuffer(b []byte, buf *bytes.Buffer) error {
return m.AppendManifestToBuffer(b, buf)
}