This repository has been archived by the owner on Nov 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fake_jxfactory.go
97 lines (83 loc) · 2.73 KB
/
fake_jxfactory.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
90
91
92
93
94
95
96
97
package fakejxfactory
import (
"github.com/jenkins-x/jx/pkg/client/clientset/versioned"
v1fake "github.com/jenkins-x/jx/pkg/client/clientset/versioned/fake"
"github.com/jenkins-x/jx/pkg/jxfactory"
"github.com/jenkins-x/jx/pkg/kube"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/kubernetes/fake"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/clientcmd"
"k8s.io/client-go/tools/clientcmd/api"
tektonclient "github.com/tektoncd/pipeline/pkg/client/clientset/versioned"
tektonfake "github.com/tektoncd/pipeline/pkg/client/clientset/versioned/fake"
corev1 "k8s.io/api/core/v1"
)
// FakeFactory represents a fake factory
type FakeFactory struct {
KubeClient kubernetes.Interface
JXClient versioned.Interface
TektonClient tektonclient.Interface
Namespace string
}
// NewFakeFactory returns a fake factory for testing
func NewFakeFactory() jxfactory.Factory {
return NewFakeFactoryWithObjects(nil, nil, "jx")
}
// NewFakeFactory returns a fake factory for testing with the given initial objects
func NewFakeFactoryWithObjects(kubeObjects []runtime.Object, jxObjects []runtime.Object, namespace string) jxfactory.Factory {
if len(kubeObjects) == 0 {
kubeObjects = append(kubeObjects, &corev1.Namespace{
ObjectMeta: metav1.ObjectMeta{
Name: namespace,
Labels: map[string]string{
"tag": "",
"team": "jx",
"env": "dev",
},
},
})
}
return &FakeFactory{
KubeClient: fake.NewSimpleClientset(kubeObjects...),
JXClient: v1fake.NewSimpleClientset(jxObjects...),
TektonClient: tektonfake.NewSimpleClientset(),
Namespace: namespace,
}
}
func (f *FakeFactory) WithBearerToken(token string) jxfactory.Factory {
return f
}
func (f *FakeFactory) ImpersonateUser(user string) jxfactory.Factory {
return f
}
func (f *FakeFactory) CreateKubeClient() (kubernetes.Interface, string, error) {
return f.KubeClient, f.Namespace, nil
}
func (f *FakeFactory) CreateKubeConfig() (*rest.Config, error) {
return &rest.Config{}, nil
}
func (f *FakeFactory) CreateJXClient() (versioned.Interface, string, error) {
return f.JXClient, f.Namespace, nil
}
func (f *FakeFactory) CreateTektonClient() (tektonclient.Interface, string, error) {
return f.TektonClient, f.Namespace, nil
}
func (f *FakeFactory) KubeConfig() kube.Kuber {
return f
}
func (f *FakeFactory) LoadConfig() (*api.Config, *clientcmd.PathOptions, error) {
return &api.Config{
CurrentContext: "current",
Contexts: map[string]*api.Context{
"current": {
Namespace: f.Namespace,
},
},
}, &clientcmd.PathOptions{}, nil
}
func (f *FakeFactory) UpdateConfig(namespace string, server string, caData string, user string, token string) error {
panic("implement me")
}