-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
🌱 Added unit tests for state_test.go #9468
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,7 +29,7 @@ import ( | |
"sigs.k8s.io/cluster-api/internal/test/builder" | ||
) | ||
|
||
func TestIsUpgrading(t *testing.T) { | ||
func TestMDIsUpgrading(t *testing.T) { | ||
g := NewWithT(t) | ||
scheme := runtime.NewScheme() | ||
g.Expect(clusterv1.AddToScheme(scheme)).To(Succeed()) | ||
|
@@ -115,7 +115,93 @@ func TestIsUpgrading(t *testing.T) { | |
} | ||
} | ||
|
||
func TestUpgrading(t *testing.T) { | ||
func TestMPIsUpgrading(t *testing.T) { | ||
g := NewWithT(t) | ||
scheme := runtime.NewScheme() | ||
g.Expect(clusterv1.AddToScheme(scheme)).To(Succeed()) | ||
|
||
tests := []struct { | ||
name string | ||
mp *clusterv1.MachinePool | ||
abdurrehman107 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
machines []*clusterv1.Machine | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We will check the noderef's kubelet version instead of the machine's version. Thus, we'll need to add a list of |
||
want bool | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "should return false if all the machines of MachinePool have the same version as the MachinePool", | ||
mp: builder.MachinePool("ns", "mp1"). | ||
WithClusterName("cluster1"). | ||
WithVersion("v1.2.3"). | ||
Build(), | ||
machines: []*clusterv1.Machine{ | ||
builder.Machine("ns", "machine1"). | ||
WithClusterName("cluster1"). | ||
WithVersion("v1.2.3"). | ||
Build(), | ||
builder.Machine("ns", "machine2"). | ||
WithClusterName("cluster1"). | ||
WithVersion("v1.2.3"). | ||
Build(), | ||
}, | ||
want: false, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "should return true if at least one of the machines of MachinePool has a different version", | ||
mp: builder.MachinePool("ns", "mp1"). | ||
WithClusterName("cluster1"). | ||
WithVersion("v1.2.3"). | ||
Build(), | ||
machines: []*clusterv1.Machine{ | ||
builder.Machine("ns", "machine1"). | ||
WithClusterName("cluster1"). | ||
WithVersion("v1.2.3"). | ||
Build(), | ||
builder.Machine("ns", "machine2"). | ||
WithClusterName("cluster1"). | ||
WithVersion("v1.2.2"). | ||
Build(), | ||
}, | ||
want: true, | ||
wantErr: false, | ||
}, | ||
{ | ||
name: "should return false if the MachinePool has no machines (creation phase)", | ||
mp: builder.MachinePool("ns", "mp1"). | ||
WithClusterName("cluster1"). | ||
WithVersion("v1.2.3"). | ||
Build(), | ||
machines: []*clusterv1.Machine{}, | ||
want: false, | ||
wantErr: false, | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
g := NewWithT(t) | ||
ctx := context.Background() | ||
objs := []client.Object{} | ||
objs = append(objs, tt.mp) | ||
for _, m := range tt.machines { | ||
objs = append(objs, m) | ||
} | ||
fakeClient := fake.NewClientBuilder().WithScheme(scheme).WithObjects(objs...).Build() | ||
mpState := &MachinePoolState{ | ||
Object: tt.mp, | ||
} | ||
got, err := mpState.IsUpgrading(ctx, fakeClient) | ||
if tt.wantErr { | ||
g.Expect(err).To(HaveOccurred()) | ||
} else { | ||
g.Expect(err).ToNot(HaveOccurred()) | ||
g.Expect(got).To(Equal(tt.want)) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func TestMDUpgrading(t *testing.T) { | ||
g := NewWithT(t) | ||
scheme := runtime.NewScheme() | ||
g.Expect(clusterv1.AddToScheme(scheme)).To(Succeed()) | ||
|
@@ -155,3 +241,44 @@ func TestUpgrading(t *testing.T) { | |
g.Expect(got).To(BeComparableTo(want)) | ||
}) | ||
} | ||
|
||
func TestMPUpgrading(t *testing.T) { | ||
g := NewWithT(t) | ||
scheme := runtime.NewScheme() | ||
g.Expect(clusterv1.AddToScheme(scheme)).To(Succeed()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You will need to add
|
||
|
||
ctx := context.Background() | ||
|
||
t.Run("should return the names of the upgrading MachinePools", func(t *testing.T) { | ||
stableMP := builder.MachinePool("ns", "stableMP"). | ||
WithClusterName("cluster1"). | ||
WithVersion("v1.2.3"). | ||
Build() | ||
stableMPMachine := builder.Machine("ns", "stableMP-machine1"). | ||
WithClusterName("cluster1"). | ||
WithVersion("v1.2.3"). | ||
Build() | ||
|
||
upgradingMP := builder.MachinePool("ns", "upgradingMP"). | ||
WithClusterName("cluster2"). | ||
WithVersion("v1.2.3"). | ||
Build() | ||
upgradingMPMachine := builder.Machine("ns", "upgradingMP-machine1"). | ||
WithClusterName("cluster2"). | ||
WithVersion("v1.2.2"). | ||
Build() | ||
|
||
objs := []client.Object{stableMP, stableMPMachine, upgradingMP, upgradingMPMachine} | ||
fakeClient := fake.NewClientBuilder().WithObjects(objs...).WithScheme(scheme).Build() | ||
|
||
mpsStateMap := MachinePoolsStateMap{ | ||
"stableMP": {Object: stableMP}, | ||
"upgradingMP": {Object: upgradingMP}, | ||
} | ||
want := []string{"upgradingMP"} | ||
|
||
got, err := mpsStateMap.Upgrading(ctx, fakeClient) | ||
g.Expect(err).ToNot(HaveOccurred()) | ||
g.Expect(got).To(BeComparableTo(want)) | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You will need to add
expv1
to the scheme as well sinceMachinePools
are part of that package instead ofclusterv1
.