1+ /*
2+ Copyright 2025 The Kubernetes Authors.
3+
4+ Licensed under the Apache License, Version 2.0 (the "License");
5+ you may not use this file except in compliance with the License.
6+ You may obtain a copy of the License at
7+
8+ http://www.apache.org/licenses/LICENSE-2.0
9+
10+ Unless required by applicable law or agreed to in writing, software
11+ distributed under the License is distributed on an "AS IS" BASIS,
12+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+ See the License for the specific language governing permissions and
14+ limitations under the License.
15+ */
16+
117package vmware
218
319import (
@@ -23,8 +39,6 @@ import (
2339 "sigs.k8s.io/controller-runtime/pkg/reconcile"
2440)
2541
26- var s = runtime .NewScheme ()
27-
2842const (
2943 clusterName = "test-cluster"
3044 clusterNamespace = "test-ns"
@@ -38,6 +52,9 @@ func TestGetExpectedVSphereMachines(t *testing.T) {
3852 g := NewWithT (t )
3953 ctx := context .Background ()
4054
55+ scheme := runtime .NewScheme ()
56+ g .Expect (clusterv1 .AddToScheme (scheme )).To (Succeed ())
57+
4158 tests := []struct {
4259 name string
4360 cluster * clusterv1.Cluster
@@ -65,7 +82,7 @@ func TestGetExpectedVSphereMachines(t *testing.T) {
6582 }
6683
6784 for _ , tt := range tests {
68- fakeClient := fake .NewClientBuilder ().WithScheme (s ).WithObjects (tt .cluster ).Build ()
85+ fakeClient := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (tt .cluster ).Build ()
6986 t .Run (tt .name , func (t * testing.T ) {
7087 g .Expect (getExpectedVSphereMachines (ctx , fakeClient , tt .cluster )).To (Equal (tt .expected ))
7188 })
@@ -76,6 +93,9 @@ func TestGetCurrentVSphereMachines(t *testing.T) {
7693 g := NewWithT (t )
7794 ctx := context .Background ()
7895
96+ scheme := runtime .NewScheme ()
97+ g .Expect (vmwarev1 .AddToScheme (scheme )).To (Succeed ())
98+
7999 // VM names are based on CAPI Machine names, not VSphereMachine names, but we use VSphereMachine here.
80100 vsm1 := newVSphereMachine ("vsm-1" , mdName1 , false , nil )
81101 vsm2 := newVSphereMachine ("vsm-2" , mdName2 , false , nil )
@@ -107,7 +127,7 @@ func TestGetCurrentVSphereMachines(t *testing.T) {
107127
108128 for _ , tt := range tests {
109129 t .Run (tt .name , func (t * testing.T ) {
110- fakeClient := fake .NewClientBuilder ().WithScheme (s ).WithObjects (tt .objects ... ).Build ()
130+ fakeClient := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (tt .objects ... ).Build ()
111131 got , err := getCurrentVSphereMachines (ctx , fakeClient , clusterNamespace , clusterName )
112132 g .Expect (err ).NotTo (HaveOccurred ())
113133 g .Expect (len (got )).To (Equal (tt .want ))
@@ -240,6 +260,10 @@ func TestVirtualMachineGroupReconciler_ReconcileFlow(t *testing.T) {
240260 g := NewWithT (t )
241261 ctx := context .Background ()
242262
263+ scheme := runtime .NewScheme ()
264+ g .Expect (clusterv1 .AddToScheme (scheme )).To (Succeed ())
265+ g .Expect (vmwarev1 .AddToScheme (scheme )).To (Succeed ())
266+
243267 // Initial objects for the successful VMG creation path (Expected: 1, Current: 1)
244268 cluster := newCluster (clusterName , clusterNamespace , true , 1 , 0 )
245269 vsm1 := newVSphereMachine ("vsm-1" , mdName1 , false , nil )
@@ -313,7 +337,7 @@ func TestVirtualMachineGroupReconciler_ReconcileFlow(t *testing.T) {
313337
314338 for _ , tt := range tests {
315339 t .Run (tt .name , func (t * testing.T ) {
316- fakeClient := fake .NewClientBuilder ().WithScheme (s ).WithObjects (tt .initialObjects ... ).Build ()
340+ fakeClient := fake .NewClientBuilder ().WithScheme (scheme ).WithObjects (tt .initialObjects ... ).Build ()
317341 reconciler := & VirtualMachineGroupReconciler {
318342 Client : fakeClient ,
319343 Recorder : record .NewFakeRecorder (1 ),
0 commit comments