@@ -31,6 +31,7 @@ import (
3131 "k8s.io/apimachinery/pkg/labels"
3232 "k8s.io/apimachinery/pkg/runtime"
3333 "sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
34+ logf "sigs.k8s.io/controller-runtime/pkg/log"
3435
3536 mysqlv1alpha1 "github.com/radondb/radondb-mysql-kubernetes/api/v1alpha1"
3637 "github.com/radondb/radondb-mysql-kubernetes/utils"
@@ -46,13 +47,13 @@ var (
4647 },
4748 }
4849 testCluster = MysqlCluster {
49- & mysqlCluster ,
50+ & mysqlCluster , logf . Log . WithName ( "mysqlcluster" ),
5051 }
5152)
5253
5354func TestNew (t * testing.T ) {
5455 want := & MysqlCluster {
55- & mysqlCluster ,
56+ & mysqlCluster , logf . Log . WithName ( "mysqlcluster" ),
5657 }
5758 assert .Equal (t , want , New (& mysqlCluster ))
5859}
@@ -69,7 +70,8 @@ func TestGetLabel(t *testing.T) {
6970 "app.kubernetes.io/instance" : "instance" ,
7071 }
7172 testCase := MysqlCluster {
72- & testMysqlCluster ,
73+ MysqlCluster : & testMysqlCluster ,
74+ log : logf .Log .WithName ("mysqlcluster" ),
7375 }
7476 want := labels.Set {
7577 "mysql.radondb.com/cluster" : "sample" ,
@@ -88,7 +90,8 @@ func TestGetLabel(t *testing.T) {
8890 "app.kubernetes.io/component" : "component" ,
8991 }
9092 testCase := MysqlCluster {
91- & testMysqlCluster ,
93+ MysqlCluster : & testMysqlCluster ,
94+ log : logf .Log .WithName ("mysqlcluster" ),
9295 }
9396 want := labels.Set {
9497 "mysql.radondb.com/cluster" : "sample" ,
@@ -107,7 +110,8 @@ func TestGetLabel(t *testing.T) {
107110 "app.kubernetes.io/part-of" : "part-of" ,
108111 }
109112 testCase := MysqlCluster {
110- & testMysqlCluster ,
113+ MysqlCluster : & testMysqlCluster ,
114+ log : logf .Log .WithName ("mysqlcluster" ),
111115 }
112116 want := labels.Set {
113117 "mysql.radondb.com/cluster" : "sample" ,
@@ -137,7 +141,8 @@ func TestGetMySQLVersion(t *testing.T) {
137141 testMysqlCluster := mysqlCluster
138142 testMysqlCluster .Spec .MysqlVersion = "8.0"
139143 testCase := MysqlCluster {
140- & testMysqlCluster ,
144+ MysqlCluster : & testMysqlCluster ,
145+ log : logf .Log .WithName ("mysqlcluster" ),
141146 }
142147 want := "8.0.25"
143148 assert .Equal (t , want , testCase .GetMySQLVersion ())
@@ -147,7 +152,8 @@ func TestGetMySQLVersion(t *testing.T) {
147152 testMysqlCluster := mysqlCluster
148153 testMysqlCluster .Spec .MysqlVersion = "5.7"
149154 testCase := MysqlCluster {
150- & testMysqlCluster ,
155+ MysqlCluster : & testMysqlCluster ,
156+ log : logf .Log .WithName ("mysqlcluster" ),
151157 }
152158 want := "5.7.34"
153159 assert .Equal (t , want , testCase .GetMySQLVersion ())
@@ -157,7 +163,8 @@ func TestGetMySQLVersion(t *testing.T) {
157163 testMysqlCluster := mysqlCluster
158164 testMysqlCluster .Spec .MysqlVersion = "5.7.34"
159165 testCase := MysqlCluster {
160- & testMysqlCluster ,
166+ MysqlCluster : & testMysqlCluster ,
167+ log : logf .Log .WithName ("mysqlcluster" ),
161168 }
162169 want := utils .InvalidMySQLVersion
163170 assert .Equal (t , want , testCase .GetMySQLVersion ())
@@ -172,7 +179,8 @@ func TestCreatePeers(t *testing.T) {
172179 testMysqlCluster .ObjectMeta .Namespace = "default"
173180 testMysqlCluster .Spec .Replicas = & replicas
174181 testCase := MysqlCluster {
175- & testMysqlCluster ,
182+ MysqlCluster : & testMysqlCluster ,
183+ log : logf .Log .WithName ("mysqlcluster" ),
176184 }
177185 want := "sample-mysql-0.sample-mysql.default:8801,sample-mysql-1.sample-mysql.default:8801"
178186 assert .Equal (t , want , testCase .CreatePeers ())
@@ -183,7 +191,7 @@ func TestCreatePeers(t *testing.T) {
183191 testMysqlCluster .ObjectMeta .Namespace = "default"
184192 testMysqlCluster .Spec .Replicas = & replicas
185193 testCase := MysqlCluster {
186- & testMysqlCluster ,
194+ MysqlCluster : & testMysqlCluster , log : logf . Log . WithName ( "mysqlcluster" ) ,
187195 }
188196 want := "sample-mysql-0.sample-mysql.default:8801,sample-mysql-1.sample-mysql.default:8801,sample-mysql-2.sample-mysql.default:8801"
189197 assert .Equal (t , want , testCase .CreatePeers ())
@@ -194,7 +202,7 @@ func TestCreatePeers(t *testing.T) {
194202 testMysqlCluster .ObjectMeta .Namespace = "default"
195203 testMysqlCluster .Spec .Replicas = & replicas
196204 testCase := MysqlCluster {
197- & testMysqlCluster ,
205+ MysqlCluster : & testMysqlCluster , log : logf . Log . WithName ( "mysqlcluster" ) ,
198206 }
199207 want := ""
200208 for i := 0 ; i < 666 ; i ++ {
@@ -212,7 +220,7 @@ func TestCreatePeers(t *testing.T) {
212220 testMysqlCluster .ObjectMeta .Namespace = "default"
213221 testMysqlCluster .Spec .Replicas = & replicas
214222 testCase := MysqlCluster {
215- & testMysqlCluster ,
223+ MysqlCluster : & testMysqlCluster , log : logf . Log . WithName ( "mysqlcluster" ) ,
216224 }
217225 want := ""
218226 assert .Equal (t , want , testCase .CreatePeers ())
@@ -223,7 +231,7 @@ func TestCreatePeers(t *testing.T) {
223231 testMysqlCluster .ObjectMeta .Namespace = "default"
224232 testMysqlCluster .Spec .Replicas = & replicas
225233 testCase := MysqlCluster {
226- & testMysqlCluster ,
234+ MysqlCluster : & testMysqlCluster , log : logf . Log . WithName ( "mysqlcluster" ) ,
227235 }
228236 want := ""
229237 assert .Equal (t , want , testCase .CreatePeers ())
@@ -234,7 +242,7 @@ func TestGetPodHostName(t *testing.T) {
234242 testMysqlCluster := mysqlCluster
235243 testMysqlCluster .ObjectMeta .Namespace = "default"
236244 testCase := MysqlCluster {
237- & testMysqlCluster ,
245+ MysqlCluster : & testMysqlCluster , log : logf . Log . WithName ( "mysqlcluster" ) ,
238246 }
239247 want0 := "sample-mysql-0.sample-mysql.default"
240248 want1 := "sample-mysql-1.sample-mysql.default"
@@ -314,7 +322,7 @@ func TestEnsureVolumes(t *testing.T) {
314322 testMysql := mysqlCluster
315323 testMysql .Spec .Persistence .Enabled = false
316324 testCase := MysqlCluster {
317- & testMysql ,
325+ MysqlCluster : & testMysql , log : logf . Log . WithName ( "mysqlcluster" ) ,
318326 }
319327 want := []corev1.Volume {
320328 {
@@ -333,7 +341,7 @@ func TestEnsureVolumes(t *testing.T) {
333341 testMysql .Spec .Persistence .Enabled = true
334342 testMysql .Spec .MysqlOpts .InitTokuDB = true
335343 testCase := MysqlCluster {
336- & testMysql ,
344+ MysqlCluster : & testMysql , log : logf . Log . WithName ( "mysqlcluster" ) ,
337345 }
338346 want := []corev1.Volume {
339347 {
@@ -353,7 +361,7 @@ func TestEnsureVolumes(t *testing.T) {
353361 testMysql := mysqlCluster
354362 testMysql .Spec .Persistence .Enabled = true
355363 testCase := MysqlCluster {
356- & testMysql ,
364+ MysqlCluster : & testMysql , log : logf . Log . WithName ( "mysqlcluster" ) ,
357365 }
358366 assert .Equal (t , volume , testCase .EnsureVolumes ())
359367 }
@@ -388,7 +396,7 @@ func TestEnsureVolumeClaimTemplates(t *testing.T) {
388396 },
389397 }
390398 testCase := MysqlCluster {
391- & testMysql ,
399+ & testMysql , logf . Log . WithName ( "mysqlcluster" ),
392400 }
393401 want := []corev1.PersistentVolumeClaim {
394402 {
@@ -433,7 +441,7 @@ func TestEnsureVolumeClaimTemplates(t *testing.T) {
433441 testMysql .Spec .Persistence .Size = "10Gi"
434442 testMysql .Spec .Persistence .StorageClass = & storageClass
435443 testCase := MysqlCluster {
436- & testMysql ,
444+ & testMysql , logf . Log . WithName ( "mysqlcluster" ),
437445 }
438446 guard := gomonkey .ApplyFunc (controllerutil .SetControllerReference , func (_ metav1.Object , _ metav1.Object , _ * runtime.Scheme ) error {
439447 return nil
@@ -451,7 +459,7 @@ func TestEnsureVolumeClaimTemplates(t *testing.T) {
451459 testMysql .Spec .Persistence .Enabled = true
452460 testMysql .Spec .Persistence .Size = "10Gi"
453461 testCase := MysqlCluster {
454- & testMysql ,
462+ & testMysql , logf . Log . WithName ( "mysqlcluster" ),
455463 }
456464 guard := gomonkey .ApplyFunc (controllerutil .SetControllerReference , func (_ metav1.Object , _ metav1.Object , _ * runtime.Scheme ) error {
457465 return fmt .Errorf ("test" )
@@ -521,7 +529,7 @@ func TestEnsureMysqlConf(t *testing.T) {
521529 {
522530 testMysqlCase := testMysql
523531 testCase := MysqlCluster {
524- & testMysqlCase ,
532+ & testMysqlCase , logf . Log . WithName ( "mysqlcluster" ),
525533 }
526534 testCase .EnsureMysqlConf ()
527535 wantSize = strconv .FormatUint (uint64 (0.45 * float64 (gb )), 10 )
@@ -539,7 +547,7 @@ func TestEnsureMysqlConf(t *testing.T) {
539547 testMysqlCase := testMysql
540548 testMysqlCase .Spec .MysqlOpts .MysqlConf ["innodb_buffer_pool_size" ] = strconv .FormatUint (uint64 (600 * mb ), 10 )
541549 testCase := MysqlCluster {
542- & testMysqlCase ,
550+ & testMysqlCase , logf . Log . WithName ( "mysqlcluster" ),
543551 }
544552 testCase .EnsureMysqlConf ()
545553 wantSize := strconv .FormatUint (uint64 (600 * float64 (mb )), 10 )
@@ -559,7 +567,7 @@ func TestEnsureMysqlConf(t *testing.T) {
559567 testMysqlCase .Spec .MysqlOpts .Resources .Requests ["memory" ] = * memoryCase
560568 testMysqlCase .Spec .MysqlOpts .MysqlConf ["innodb_buffer_pool_size" ] = strconv .FormatUint (uint64 (1.7 * float64 (gb )), 10 )
561569 testCase := MysqlCluster {
562- & testMysqlCase ,
570+ & testMysqlCase , logf . Log . WithName ( "mysqlcluster" ),
563571 }
564572 testCase .EnsureMysqlConf ()
565573 wantSize := strconv .FormatUint (uint64 (1.6 * float64 (gb )), 10 )
@@ -578,7 +586,7 @@ func TestEnsureMysqlConf(t *testing.T) {
578586 testMysqlCase .Spec .MysqlOpts .Resources .Requests ["memory" ] = * memoryCase
579587 testMysqlCase .Spec .MysqlOpts .MysqlConf ["innodb_buffer_pool_size" ] = strconv .FormatUint (uint64 (1.7 * float64 (gb )), 10 )
580588 testCase := MysqlCluster {
581- & testMysqlCase ,
589+ & testMysqlCase , logf . Log . WithName ( "mysqlcluster" ),
582590 }
583591 testCase .EnsureMysqlConf ()
584592 wantSize := strconv .FormatUint (uint64 (1.2 * float64 (gb )), 10 )
@@ -599,7 +607,7 @@ func TestEnsureMysqlConf(t *testing.T) {
599607 testMysqlCase .Spec .MysqlOpts .Resources .Limits ["cpu" ] = * limitCpucorev1sCase
600608 testMysqlCase .Spec .MysqlOpts .Resources .Requests ["memory" ] = * memoryCase
601609 testCase := MysqlCluster {
602- & testMysqlCase ,
610+ & testMysqlCase , logf . Log . WithName ( "mysqlcluster" ),
603611 }
604612 testCase .EnsureMysqlConf ()
605613 wantSize := strconv .FormatUint (uint64 (2 * float64 (gb )), 10 )
0 commit comments