@@ -6,25 +6,25 @@ import (
6
6
"testing"
7
7
8
8
"github.com/stretchr/testify/assert"
9
- v1beta1 "k8s.io/api/batch/v1beta1 "
9
+ batchv1 "k8s.io/api/batch/v1 "
10
10
v1 "k8s.io/api/core/v1"
11
11
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
12
12
"k8s.io/client-go/kubernetes/fake"
13
13
14
14
k8sapiv1 "github.com/lyft/clutch/backend/api/k8s/v1"
15
15
)
16
16
17
- func testCronService () * svc {
18
- cron := & v1beta1.CronJob {
17
+ func testCronService (t * testing.T ) * svc {
18
+ var cs * fake.Clientset
19
+ cron := & batchv1.CronJob {
19
20
ObjectMeta : metav1.ObjectMeta {
20
21
Name : "testing-cron-name" ,
21
22
Namespace : "testing-namespace" ,
22
23
Labels : map [string ]string {"test" : "foo" },
23
24
Annotations : map [string ]string {"test" : "bar" },
24
25
},
25
26
}
26
-
27
- cs := fake .NewSimpleClientset (cron )
27
+ cs = fake .NewSimpleClientset (cron )
28
28
return & svc {
29
29
manager : & managerImpl {
30
30
clientsets : map [string ]* ctxClientsetImpl {"foo" : {
@@ -37,18 +37,19 @@ func testCronService() *svc {
37
37
}
38
38
39
39
func TestDescribeCron (t * testing.T ) {
40
- s := testCronService ()
40
+ s := testCronService (t )
41
41
cron , err := s .DescribeCronJob (context .Background (), "foo" , "core-testing" , "testing-namespace" , "testing-cron-name" )
42
42
assert .NoError (t , err )
43
43
assert .NotNil (t , cron )
44
44
}
45
45
46
46
func TestListCron (t * testing.T ) {
47
- s := testCronService ()
47
+ s := testCronService (t )
48
48
opts := & k8sapiv1.ListOptions {Labels : map [string ]string {"test" : "foo" }}
49
49
list , err := s .ListCronJobs (context .Background (), "foo" , "core-testing" , "testing-namespace" , opts )
50
50
assert .NoError (t , err )
51
51
assert .Equal (t , 1 , len (list ))
52
+
52
53
// Not Found
53
54
opts = & k8sapiv1.ListOptions {Labels : map [string ]string {"unknown" : "bar" }}
54
55
list , err = s .ListCronJobs (context .Background (), "foo" , "core-testing" , "testing-namespace" , opts )
@@ -57,7 +58,7 @@ func TestListCron(t *testing.T) {
57
58
}
58
59
59
60
func TestDeleteCron (t * testing.T ) {
60
- s := testCronService ()
61
+ s := testCronService (t )
61
62
// Not found.
62
63
err := s .DeleteCronJob (context .Background (), "foo" , "core-testing" , "testing-namespace" , "abc" )
63
64
assert .Error (t , err )
@@ -78,14 +79,14 @@ func TestProtoForCron(t *testing.T) {
78
79
inputClusterName string
79
80
expectedClusterName string
80
81
expectedName string
81
- cron * v1beta1 .CronJob
82
+ cron * batchv1 .CronJob
82
83
}{
83
84
{
84
85
id : "clustername already set" ,
85
86
inputClusterName : "abc" ,
86
87
expectedClusterName : "production" ,
87
88
expectedName : "test1" ,
88
- cron : & v1beta1 .CronJob {
89
+ cron : & batchv1 .CronJob {
89
90
ObjectMeta : metav1.ObjectMeta {
90
91
Labels : map [string ]string {
91
92
clutchLabelClusterName : "production" ,
@@ -99,20 +100,20 @@ func TestProtoForCron(t *testing.T) {
99
100
inputClusterName : "staging" ,
100
101
expectedClusterName : "staging" ,
101
102
expectedName : "test2" ,
102
- cron : & v1beta1 .CronJob {
103
+ cron : & batchv1 .CronJob {
103
104
ObjectMeta : metav1.ObjectMeta {
104
105
Labels : map [string ]string {
105
106
clutchLabelClusterName : "" ,
106
107
},
107
108
Name : "test2" ,
108
109
},
109
- Spec : v1beta1 .CronJobSpec {
110
- ConcurrencyPolicy : v1beta1 .AllowConcurrent ,
110
+ Spec : batchv1 .CronJobSpec {
111
+ ConcurrencyPolicy : batchv1 .AllowConcurrent ,
111
112
Schedule : "5 4 * * *" ,
112
113
Suspend : & []bool {true }[0 ],
113
114
StartingDeadlineSeconds : & []int64 {69 }[0 ],
114
115
},
115
- Status : v1beta1 .CronJobStatus {
116
+ Status : batchv1 .CronJobStatus {
116
117
Active : []v1.ObjectReference {{}, {}},
117
118
},
118
119
},
0 commit comments