@@ -31,6 +31,7 @@ import (
31
31
"k8s.io/apimachinery/pkg/labels"
32
32
"k8s.io/apimachinery/pkg/runtime"
33
33
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
34
+ logf "sigs.k8s.io/controller-runtime/pkg/log"
34
35
35
36
mysqlv1alpha1 "github.com/radondb/radondb-mysql-kubernetes/api/v1alpha1"
36
37
"github.com/radondb/radondb-mysql-kubernetes/utils"
@@ -46,13 +47,13 @@ var (
46
47
},
47
48
}
48
49
testCluster = MysqlCluster {
49
- & mysqlCluster ,
50
+ & mysqlCluster , logf . Log . WithName ( "mysqlcluster" ),
50
51
}
51
52
)
52
53
53
54
func TestNew (t * testing.T ) {
54
55
want := & MysqlCluster {
55
- & mysqlCluster ,
56
+ & mysqlCluster , logf . Log . WithName ( "mysqlcluster" ),
56
57
}
57
58
assert .Equal (t , want , New (& mysqlCluster ))
58
59
}
@@ -69,7 +70,8 @@ func TestGetLabel(t *testing.T) {
69
70
"app.kubernetes.io/instance" : "instance" ,
70
71
}
71
72
testCase := MysqlCluster {
72
- & testMysqlCluster ,
73
+ MysqlCluster : & testMysqlCluster ,
74
+ log : logf .Log .WithName ("mysqlcluster" ),
73
75
}
74
76
want := labels.Set {
75
77
"mysql.radondb.com/cluster" : "sample" ,
@@ -88,7 +90,8 @@ func TestGetLabel(t *testing.T) {
88
90
"app.kubernetes.io/component" : "component" ,
89
91
}
90
92
testCase := MysqlCluster {
91
- & testMysqlCluster ,
93
+ MysqlCluster : & testMysqlCluster ,
94
+ log : logf .Log .WithName ("mysqlcluster" ),
92
95
}
93
96
want := labels.Set {
94
97
"mysql.radondb.com/cluster" : "sample" ,
@@ -107,7 +110,8 @@ func TestGetLabel(t *testing.T) {
107
110
"app.kubernetes.io/part-of" : "part-of" ,
108
111
}
109
112
testCase := MysqlCluster {
110
- & testMysqlCluster ,
113
+ MysqlCluster : & testMysqlCluster ,
114
+ log : logf .Log .WithName ("mysqlcluster" ),
111
115
}
112
116
want := labels.Set {
113
117
"mysql.radondb.com/cluster" : "sample" ,
@@ -137,7 +141,8 @@ func TestGetMySQLVersion(t *testing.T) {
137
141
testMysqlCluster := mysqlCluster
138
142
testMysqlCluster .Spec .MysqlVersion = "8.0"
139
143
testCase := MysqlCluster {
140
- & testMysqlCluster ,
144
+ MysqlCluster : & testMysqlCluster ,
145
+ log : logf .Log .WithName ("mysqlcluster" ),
141
146
}
142
147
want := "8.0.25"
143
148
assert .Equal (t , want , testCase .GetMySQLVersion ())
@@ -147,7 +152,8 @@ func TestGetMySQLVersion(t *testing.T) {
147
152
testMysqlCluster := mysqlCluster
148
153
testMysqlCluster .Spec .MysqlVersion = "5.7"
149
154
testCase := MysqlCluster {
150
- & testMysqlCluster ,
155
+ MysqlCluster : & testMysqlCluster ,
156
+ log : logf .Log .WithName ("mysqlcluster" ),
151
157
}
152
158
want := "5.7.34"
153
159
assert .Equal (t , want , testCase .GetMySQLVersion ())
@@ -157,7 +163,8 @@ func TestGetMySQLVersion(t *testing.T) {
157
163
testMysqlCluster := mysqlCluster
158
164
testMysqlCluster .Spec .MysqlVersion = "5.7.34"
159
165
testCase := MysqlCluster {
160
- & testMysqlCluster ,
166
+ MysqlCluster : & testMysqlCluster ,
167
+ log : logf .Log .WithName ("mysqlcluster" ),
161
168
}
162
169
want := utils .InvalidMySQLVersion
163
170
assert .Equal (t , want , testCase .GetMySQLVersion ())
@@ -172,7 +179,8 @@ func TestCreatePeers(t *testing.T) {
172
179
testMysqlCluster .ObjectMeta .Namespace = "default"
173
180
testMysqlCluster .Spec .Replicas = & replicas
174
181
testCase := MysqlCluster {
175
- & testMysqlCluster ,
182
+ MysqlCluster : & testMysqlCluster ,
183
+ log : logf .Log .WithName ("mysqlcluster" ),
176
184
}
177
185
want := "sample-mysql-0.sample-mysql.default:8801,sample-mysql-1.sample-mysql.default:8801"
178
186
assert .Equal (t , want , testCase .CreatePeers ())
@@ -183,7 +191,7 @@ func TestCreatePeers(t *testing.T) {
183
191
testMysqlCluster .ObjectMeta .Namespace = "default"
184
192
testMysqlCluster .Spec .Replicas = & replicas
185
193
testCase := MysqlCluster {
186
- & testMysqlCluster ,
194
+ MysqlCluster : & testMysqlCluster , log : logf . Log . WithName ( "mysqlcluster" ) ,
187
195
}
188
196
want := "sample-mysql-0.sample-mysql.default:8801,sample-mysql-1.sample-mysql.default:8801,sample-mysql-2.sample-mysql.default:8801"
189
197
assert .Equal (t , want , testCase .CreatePeers ())
@@ -194,7 +202,7 @@ func TestCreatePeers(t *testing.T) {
194
202
testMysqlCluster .ObjectMeta .Namespace = "default"
195
203
testMysqlCluster .Spec .Replicas = & replicas
196
204
testCase := MysqlCluster {
197
- & testMysqlCluster ,
205
+ MysqlCluster : & testMysqlCluster , log : logf . Log . WithName ( "mysqlcluster" ) ,
198
206
}
199
207
want := ""
200
208
for i := 0 ; i < 666 ; i ++ {
@@ -212,7 +220,7 @@ func TestCreatePeers(t *testing.T) {
212
220
testMysqlCluster .ObjectMeta .Namespace = "default"
213
221
testMysqlCluster .Spec .Replicas = & replicas
214
222
testCase := MysqlCluster {
215
- & testMysqlCluster ,
223
+ MysqlCluster : & testMysqlCluster , log : logf . Log . WithName ( "mysqlcluster" ) ,
216
224
}
217
225
want := ""
218
226
assert .Equal (t , want , testCase .CreatePeers ())
@@ -223,7 +231,7 @@ func TestCreatePeers(t *testing.T) {
223
231
testMysqlCluster .ObjectMeta .Namespace = "default"
224
232
testMysqlCluster .Spec .Replicas = & replicas
225
233
testCase := MysqlCluster {
226
- & testMysqlCluster ,
234
+ MysqlCluster : & testMysqlCluster , log : logf . Log . WithName ( "mysqlcluster" ) ,
227
235
}
228
236
want := ""
229
237
assert .Equal (t , want , testCase .CreatePeers ())
@@ -234,7 +242,7 @@ func TestGetPodHostName(t *testing.T) {
234
242
testMysqlCluster := mysqlCluster
235
243
testMysqlCluster .ObjectMeta .Namespace = "default"
236
244
testCase := MysqlCluster {
237
- & testMysqlCluster ,
245
+ MysqlCluster : & testMysqlCluster , log : logf . Log . WithName ( "mysqlcluster" ) ,
238
246
}
239
247
want0 := "sample-mysql-0.sample-mysql.default"
240
248
want1 := "sample-mysql-1.sample-mysql.default"
@@ -314,7 +322,7 @@ func TestEnsureVolumes(t *testing.T) {
314
322
testMysql := mysqlCluster
315
323
testMysql .Spec .Persistence .Enabled = false
316
324
testCase := MysqlCluster {
317
- & testMysql ,
325
+ MysqlCluster : & testMysql , log : logf . Log . WithName ( "mysqlcluster" ) ,
318
326
}
319
327
want := []corev1.Volume {
320
328
{
@@ -333,7 +341,7 @@ func TestEnsureVolumes(t *testing.T) {
333
341
testMysql .Spec .Persistence .Enabled = true
334
342
testMysql .Spec .MysqlOpts .InitTokuDB = true
335
343
testCase := MysqlCluster {
336
- & testMysql ,
344
+ MysqlCluster : & testMysql , log : logf . Log . WithName ( "mysqlcluster" ) ,
337
345
}
338
346
want := []corev1.Volume {
339
347
{
@@ -353,7 +361,7 @@ func TestEnsureVolumes(t *testing.T) {
353
361
testMysql := mysqlCluster
354
362
testMysql .Spec .Persistence .Enabled = true
355
363
testCase := MysqlCluster {
356
- & testMysql ,
364
+ MysqlCluster : & testMysql , log : logf . Log . WithName ( "mysqlcluster" ) ,
357
365
}
358
366
assert .Equal (t , volume , testCase .EnsureVolumes ())
359
367
}
@@ -388,7 +396,7 @@ func TestEnsureVolumeClaimTemplates(t *testing.T) {
388
396
},
389
397
}
390
398
testCase := MysqlCluster {
391
- & testMysql ,
399
+ & testMysql , logf . Log . WithName ( "mysqlcluster" ),
392
400
}
393
401
want := []corev1.PersistentVolumeClaim {
394
402
{
@@ -433,7 +441,7 @@ func TestEnsureVolumeClaimTemplates(t *testing.T) {
433
441
testMysql .Spec .Persistence .Size = "10Gi"
434
442
testMysql .Spec .Persistence .StorageClass = & storageClass
435
443
testCase := MysqlCluster {
436
- & testMysql ,
444
+ & testMysql , logf . Log . WithName ( "mysqlcluster" ),
437
445
}
438
446
guard := gomonkey .ApplyFunc (controllerutil .SetControllerReference , func (_ metav1.Object , _ metav1.Object , _ * runtime.Scheme ) error {
439
447
return nil
@@ -451,7 +459,7 @@ func TestEnsureVolumeClaimTemplates(t *testing.T) {
451
459
testMysql .Spec .Persistence .Enabled = true
452
460
testMysql .Spec .Persistence .Size = "10Gi"
453
461
testCase := MysqlCluster {
454
- & testMysql ,
462
+ & testMysql , logf . Log . WithName ( "mysqlcluster" ),
455
463
}
456
464
guard := gomonkey .ApplyFunc (controllerutil .SetControllerReference , func (_ metav1.Object , _ metav1.Object , _ * runtime.Scheme ) error {
457
465
return fmt .Errorf ("test" )
@@ -521,7 +529,7 @@ func TestEnsureMysqlConf(t *testing.T) {
521
529
{
522
530
testMysqlCase := testMysql
523
531
testCase := MysqlCluster {
524
- & testMysqlCase ,
532
+ & testMysqlCase , logf . Log . WithName ( "mysqlcluster" ),
525
533
}
526
534
testCase .EnsureMysqlConf ()
527
535
wantSize = strconv .FormatUint (uint64 (0.45 * float64 (gb )), 10 )
@@ -539,7 +547,7 @@ func TestEnsureMysqlConf(t *testing.T) {
539
547
testMysqlCase := testMysql
540
548
testMysqlCase .Spec .MysqlOpts .MysqlConf ["innodb_buffer_pool_size" ] = strconv .FormatUint (uint64 (600 * mb ), 10 )
541
549
testCase := MysqlCluster {
542
- & testMysqlCase ,
550
+ & testMysqlCase , logf . Log . WithName ( "mysqlcluster" ),
543
551
}
544
552
testCase .EnsureMysqlConf ()
545
553
wantSize := strconv .FormatUint (uint64 (600 * float64 (mb )), 10 )
@@ -559,7 +567,7 @@ func TestEnsureMysqlConf(t *testing.T) {
559
567
testMysqlCase .Spec .MysqlOpts .Resources .Requests ["memory" ] = * memoryCase
560
568
testMysqlCase .Spec .MysqlOpts .MysqlConf ["innodb_buffer_pool_size" ] = strconv .FormatUint (uint64 (1.7 * float64 (gb )), 10 )
561
569
testCase := MysqlCluster {
562
- & testMysqlCase ,
570
+ & testMysqlCase , logf . Log . WithName ( "mysqlcluster" ),
563
571
}
564
572
testCase .EnsureMysqlConf ()
565
573
wantSize := strconv .FormatUint (uint64 (1.6 * float64 (gb )), 10 )
@@ -578,7 +586,7 @@ func TestEnsureMysqlConf(t *testing.T) {
578
586
testMysqlCase .Spec .MysqlOpts .Resources .Requests ["memory" ] = * memoryCase
579
587
testMysqlCase .Spec .MysqlOpts .MysqlConf ["innodb_buffer_pool_size" ] = strconv .FormatUint (uint64 (1.7 * float64 (gb )), 10 )
580
588
testCase := MysqlCluster {
581
- & testMysqlCase ,
589
+ & testMysqlCase , logf . Log . WithName ( "mysqlcluster" ),
582
590
}
583
591
testCase .EnsureMysqlConf ()
584
592
wantSize := strconv .FormatUint (uint64 (1.2 * float64 (gb )), 10 )
@@ -599,7 +607,7 @@ func TestEnsureMysqlConf(t *testing.T) {
599
607
testMysqlCase .Spec .MysqlOpts .Resources .Limits ["cpu" ] = * limitCpucorev1sCase
600
608
testMysqlCase .Spec .MysqlOpts .Resources .Requests ["memory" ] = * memoryCase
601
609
testCase := MysqlCluster {
602
- & testMysqlCase ,
610
+ & testMysqlCase , logf . Log . WithName ( "mysqlcluster" ),
603
611
}
604
612
testCase .EnsureMysqlConf ()
605
613
wantSize := strconv .FormatUint (uint64 (2 * float64 (gb )), 10 )
0 commit comments