forked from argoproj/argo-cd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mock.go
63 lines (50 loc) · 1.76 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
package kubetest
import (
"context"
"k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/apimachinery/pkg/watch"
"k8s.io/client-go/rest"
)
type KubectlOutput struct {
Output string
Err error
}
type MockKubectlCmd struct {
APIResources []*v1.APIResourceList
Resources []*unstructured.Unstructured
Commands map[string]KubectlOutput
Events chan watch.Event
}
func (k MockKubectlCmd) GetAPIResources(config *rest.Config) ([]*v1.APIResourceList, error) {
return k.APIResources, nil
}
func (k MockKubectlCmd) GetResources(config *rest.Config, namespace string) ([]*unstructured.Unstructured, error) {
return k.Resources, nil
}
func (k MockKubectlCmd) GetResource(config *rest.Config, gvk schema.GroupVersionKind, name string, namespace string) (*unstructured.Unstructured, error) {
return nil, nil
}
func (k MockKubectlCmd) WatchResources(
ctx context.Context, config *rest.Config, namespace string) (chan watch.Event, error) {
return k.Events, nil
}
func (k MockKubectlCmd) DeleteResource(config *rest.Config, gvk schema.GroupVersionKind, name string, namespace string, forceDelete bool) error {
command, ok := k.Commands[name]
if !ok {
return nil
}
return command.Err
}
func (k MockKubectlCmd) ApplyResource(config *rest.Config, obj *unstructured.Unstructured, namespace string, dryRun, force bool) (string, error) {
command, ok := k.Commands[obj.GetName()]
if !ok {
return "", nil
}
return command.Output, command.Err
}
// ConvertToVersion converts an unstructured object into the specified group/version
func (k MockKubectlCmd) ConvertToVersion(obj *unstructured.Unstructured, group, version string) (*unstructured.Unstructured, error) {
return obj, nil
}