Skip to content

Commit 03a5cef

Browse files
sdminonneclaude
andcommitted
test(nodepool): add coverage for osImageStream config hash, CAPI status, and error path
- Add "When rhelStream is set, it should change the hash" case to TestHash and TestHashWithoutVersion, verifying that changing rhelStream changes the hash and that empty rhelStream preserves backward-compatible values. - Add expectedOSImageStream assertion to TestReconcileMachineDeploymentStatus, verifying status.osImageStream is set to rhel-9 on rollout completion with a 4.x release. - Add error path case to TestGetRHELStream for unparseable version strings. Signed-off-by: Salvatore Dario Minonne <sminonne@redhat.com> Commit-Message-Assisted-by: Claude (via Claude Code) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent afe4b10 commit 03a5cef

3 files changed

Lines changed: 41 additions & 1 deletion

File tree

hypershift-operator/controllers/nodepool/capi_test.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2641,14 +2641,15 @@ func TestReconcileMachineDeploymentStatus(t *testing.T) {
26412641
nodePoolAnnotations map[string]string
26422642
targetVersion string
26432643
expectedVersion string
2644+
expectedOSImageStream string
26442645
expectedReplicas int32
26452646
expectedConfigAnnotation bool
26462647
expectedTemplateAnnotation bool
26472648
expectedReadyConditionStatus corev1.ConditionStatus
26482649
expectedReadyConditionSet bool
26492650
}{
26502651
{
2651-
name: "When MachineDeployment is complete, it should update nodePool version and annotations",
2652+
name: "When MachineDeployment is complete, it should update nodePool version and osImageStream",
26522653
machineDeployment: &capiv1.MachineDeployment{
26532654
ObjectMeta: metav1.ObjectMeta{Generation: 1},
26542655
Spec: capiv1.MachineDeploymentSpec{
@@ -2666,6 +2667,7 @@ func TestReconcileMachineDeploymentStatus(t *testing.T) {
26662667
nodePoolAnnotations: map[string]string{},
26672668
targetVersion: "4.17.0",
26682669
expectedVersion: "4.17.0",
2670+
expectedOSImageStream: "rhel-9",
26692671
expectedReplicas: 3,
26702672
expectedConfigAnnotation: true,
26712673
expectedTemplateAnnotation: true,
@@ -2766,6 +2768,10 @@ func TestReconcileMachineDeploymentStatus(t *testing.T) {
27662768
g.Expect(nodePool.Status.Replicas).To(Equal(tc.expectedReplicas))
27672769
g.Expect(nodePool.Status.Version).To(Equal(tc.expectedVersion))
27682770

2771+
if tc.expectedOSImageStream != "" {
2772+
g.Expect(nodePool.Status.OSImageStream.Name).To(Equal(tc.expectedOSImageStream))
2773+
}
2774+
27692775
if tc.expectedConfigAnnotation {
27702776
g.Expect(nodePool.Annotations).To(HaveKey(nodePoolAnnotationCurrentConfig))
27712777
}

hypershift-operator/controllers/nodepool/config_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,7 @@ func TestHash(t *testing.T) {
434434
pullSecretName string
435435
additionalTrustBundleName string
436436
globalConfig string
437+
rhelStream string
437438
expected string
438439
}{
439440
{
@@ -490,6 +491,16 @@ func TestHash(t *testing.T) {
490491
globalConfig: "different",
491492
expected: "e916ddfe",
492493
},
494+
{
495+
name: "When rhelStream is set, it should change the hash",
496+
mcoRawConfig: baseCaseMCORawConfig,
497+
releaseVersion: baseCaseReleaseVersion,
498+
pullSecretName: baseCasePullSecretName,
499+
additionalTrustBundleName: baseCaseAdditionalTrustBundleName,
500+
globalConfig: baseCaseGlobalConfig,
501+
rhelStream: "rhel-10",
502+
expected: "2dbbd41b",
503+
},
493504
}
494505

495506
for _, tc := range testCases {
@@ -508,6 +519,7 @@ func TestHash(t *testing.T) {
508519
pullSecretName: tc.pullSecretName,
509520
additionalTrustBundleName: tc.additionalTrustBundleName,
510521
globalConfig: tc.globalConfig,
522+
rhelStream: tc.rhelStream,
511523
releaseImage: releaseImage,
512524
},
513525
}
@@ -536,6 +548,7 @@ func TestHashWithoutVersion(t *testing.T) {
536548
pullSecretName string
537549
additionalTrustBundleName string
538550
globalConfig string
551+
rhelStream string
539552
expected string
540553
}{
541554
{
@@ -594,6 +607,16 @@ func TestHashWithoutVersion(t *testing.T) {
594607
globalConfig: "different",
595608
expected: baseCaseHash,
596609
},
610+
{
611+
name: "When rhelStream is set, it should change the hash",
612+
mcoRawConfig: baseCaseMCORawConfig,
613+
releaseVersion: baseCaseReleaseVersion,
614+
pullSecretName: baseCasePullSecretName,
615+
additionalTrustBundleName: baseCaseAdditionalTrustBundleName,
616+
globalConfig: baseCaseGlobalConfig,
617+
rhelStream: "rhel-10",
618+
expected: "671fe083",
619+
},
597620
}
598621

599622
for _, tc := range testCases {
@@ -612,6 +635,7 @@ func TestHashWithoutVersion(t *testing.T) {
612635
pullSecretName: tc.pullSecretName,
613636
additionalTrustBundleName: tc.additionalTrustBundleName,
614637
globalConfig: tc.globalConfig,
638+
rhelStream: tc.rhelStream,
615639
releaseImage: releaseImage,
616640
},
617641
}

hypershift-operator/controllers/nodepool/osstream_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,16 @@ func TestGetRHELStream(t *testing.T) {
6262
},
6363
expectedStream: "rhel-10",
6464
},
65+
{
66+
name: "When spec.osImageStream.Name is empty and version is unparseable, it should return an error",
67+
nodePool: &hyperv1.NodePool{
68+
Spec: hyperv1.NodePoolSpec{},
69+
},
70+
releaseImage: &releaseinfo.ReleaseImage{
71+
ImageStream: &imageapi.ImageStream{ObjectMeta: metav1.ObjectMeta{Name: "not-a-version"}},
72+
},
73+
expectErr: true,
74+
},
6575
}
6676

6777
for _, tc := range testCases {

0 commit comments

Comments
 (0)