-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample_group_b_test.go
90 lines (73 loc) · 2.61 KB
/
example_group_b_test.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
package pkg
import (
"context"
"testing"
egbApi "github.com/Yu-Jack/wrangler-test/apis/example.group.b/v1beta1"
"github.com/Yu-Jack/wrangler-test/generated/clientset/versioned/fake"
"github.com/Yu-Jack/wrangler-test/generated/clientset/versioned/typed/example.group.b/v1beta1"
"github.com/stretchr/testify/suite"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/watch"
)
type ExampleGroupBSuite struct {
suite.Suite
namespace string
clientSet *fake.Clientset
egbf *exampleGroupBFactory
}
func TestExampleTestSuite(t *testing.T) {
suite.Run(t, new(ExampleGroupBSuite))
}
func (s *ExampleGroupBSuite) SetupSuite() {
s.namespace = "test"
s.clientSet = fake.NewSimpleClientset()
s.egbf = &exampleGroupBFactory{
cronJobClient: FakeExampleGroupBClient(s.clientSet.ExampleV1beta1().CronJobs),
}
}
func (s *ExampleGroupBSuite) TestOnChange() {
description := "normal case"
cronJob := &egbApi.CronJob{
ObjectMeta: metav1.ObjectMeta{
Name: "test-cronjob-01",
Namespace: s.namespace,
},
Spec: egbApi.CronJobSpec{
Foo: "this is cron job",
},
}
_, err := s.clientSet.ExampleV1beta1().CronJobs(s.namespace).Create(context.TODO(), cronJob, metav1.CreateOptions{})
s.Require().NoError(err, description)
newCronJob, err := s.egbf.OnChange("", cronJob)
s.Require().NoError(err, description)
s.Require().Equal(fixedFoo, newCronJob.Spec.Foo, description)
}
type FakeExampleGroupBClient func(namespace string) v1beta1.CronJobInterface
func (f FakeExampleGroupBClient) Create(job *egbApi.CronJob) (*egbApi.CronJob, error) {
//TODO implement me
panic("implement me")
}
func (f FakeExampleGroupBClient) Update(job *egbApi.CronJob) (*egbApi.CronJob, error) {
return f(job.Namespace).Update(context.TODO(), job, metav1.UpdateOptions{})
}
func (f FakeExampleGroupBClient) Delete(namespace, name string, options *metav1.DeleteOptions) error {
//TODO implement me
panic("implement me")
}
func (f FakeExampleGroupBClient) Get(namespace, name string, options metav1.GetOptions) (*egbApi.CronJob, error) {
//TODO implement me
panic("implement me")
}
func (f FakeExampleGroupBClient) List(namespace string, opts metav1.ListOptions) (*egbApi.CronJobList, error) {
//TODO implement me
panic("implement me")
}
func (f FakeExampleGroupBClient) Watch(namespace string, opts metav1.ListOptions) (watch.Interface, error) {
//TODO implement me
panic("implement me")
}
func (f FakeExampleGroupBClient) Patch(namespace, name string, pt types.PatchType, data []byte, subresources ...string) (result *egbApi.CronJob, err error) {
//TODO implement me
panic("implement me")
}