Skip to content

Commit

Permalink
Test fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
dgoodwin committed Jun 7, 2021
1 parent 51493da commit c7d6052
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2491,10 +2491,11 @@ func testEmptyClusterDeployment() *hivev1.ClusterDeployment {
Kind: "ClusterDeployment",
},
ObjectMeta: metav1.ObjectMeta{
Name: testName,
Namespace: testNamespace,
Finalizers: []string{hivev1.FinalizerDeprovision},
UID: types.UID("1234"),
Name: testName,
Namespace: testNamespace,
Finalizers: []string{hivev1.FinalizerDeprovision},
UID: types.UID("1234"),
ResourceVersion: "999",
},
}
return cd
Expand Down Expand Up @@ -2708,6 +2709,7 @@ func testProvision() *hivev1.ClusterProvision {
Labels: map[string]string{
constants.ClusterDeploymentNameLabel: testName,
},
ResourceVersion: "999",
},
Spec: hivev1.ClusterProvisionSpec{
ClusterDeploymentRef: corev1.LocalObjectReference{
Expand Down
32 changes: 16 additions & 16 deletions pkg/controller/velerobackup/velerobackup_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ func TestReconcile(t *testing.T) {
},
expectedResult: reconcile.Result{},
expectedObjects: []runtime.Object{
testclusterdeployment.Build(clusterDeploymentBase()),
testsyncset.Build(syncSetBase()),
testdnszone.Build(dnsZoneBase()),
testclusterdeployment.Build(clusterDeploymentBase(), testclusterdeployment.WithResourceVersion("999")),
testsyncset.Build(syncSetBase(), testsyncset.WithResourceVersion("999")),
testdnszone.Build(dnsZoneBase(), testdnszone.WithResourceVersion("999")),
testcheckpoint.Build(checkpointBase(), testcheckpoint.WithLastBackupChecksum(calculateRuntimeObjectsChecksum(
[]runtime.Object{
testclusterdeployment.Build(clusterDeploymentBase()),
Expand Down Expand Up @@ -150,7 +150,7 @@ func TestReconcile(t *testing.T) {
},
expectedResult: reconcile.Result{},
expectedObjects: []runtime.Object{
testclusterdeployment.Build(clusterDeploymentBase()),
testclusterdeployment.Build(clusterDeploymentBase(), testclusterdeployment.WithResourceVersion("999")),
testcheckpoint.Build(checkpointBase(),
testcheckpoint.WithLastBackupRef(hivev1.BackupReference{Name: "notarealbackup", Namespace: namespace}),
testcheckpoint.WithLastBackupTime(fiveHoursAgo),
Expand Down Expand Up @@ -186,8 +186,8 @@ func TestReconcile(t *testing.T) {
RequeueAfter: ((3 * time.Minute) - twoMinuteDuration),
},
expectedObjects: []runtime.Object{
testclusterdeployment.Build(clusterDeploymentBase()),
testsyncset.Build(syncSetBase()),
testclusterdeployment.Build(clusterDeploymentBase(), testclusterdeployment.WithResourceVersion("999")),
testsyncset.Build(syncSetBase(), testsyncset.WithResourceVersion("999")),
testcheckpoint.Build(checkpointBase(),
testcheckpoint.WithLastBackupRef(hivev1.BackupReference{Name: "notarealbackup", Namespace: namespace}),
testcheckpoint.WithLastBackupTime(twoMinutesAgo),
Expand Down Expand Up @@ -218,8 +218,8 @@ func TestReconcile(t *testing.T) {
},
expectedResult: reconcile.Result{},
expectedObjects: []runtime.Object{
testclusterdeployment.Build(clusterDeploymentBase()),
testsyncset.Build(syncSetBase()),
testclusterdeployment.Build(clusterDeploymentBase(), testclusterdeployment.WithResourceVersion("999")),
testsyncset.Build(syncSetBase(), testsyncset.WithResourceVersion("999")),
testcheckpoint.Build(checkpointBase(), testcheckpoint.WithLastBackupChecksum(calculateRuntimeObjectsChecksum(
[]runtime.Object{
testclusterdeployment.Build(clusterDeploymentBase()),
Expand Down Expand Up @@ -249,8 +249,8 @@ func TestReconcile(t *testing.T) {
},
expectedResult: reconcile.Result{},
expectedObjects: []runtime.Object{
testclusterdeployment.Build(clusterDeploymentBase()),
testsyncset.Build(syncSetBase()),
testclusterdeployment.Build(clusterDeploymentBase(), testclusterdeployment.WithResourceVersion("999")),
testsyncset.Build(syncSetBase(), testsyncset.WithResourceVersion("999")),
testcheckpoint.Build(checkpointBase(), testcheckpoint.WithLastBackupChecksum(calculateRuntimeObjectsChecksum(
[]runtime.Object{
testclusterdeployment.Build(clusterDeploymentBase()),
Expand Down Expand Up @@ -331,17 +331,17 @@ func TestGetRuntimeObjects(t *testing.T) {
testclusterdeployment.Build(clusterDeploymentBase()),
},
expectedObjects: []runtime.Object{
testclusterdeployment.Build(clusterDeploymentBase()),
testclusterdeployment.Build(clusterDeploymentBase(), testclusterdeployment.WithResourceVersion("999")),
},
},
{
name: "2 ClusterDeployments in different namespaces",
existingObjects: []runtime.Object{
testclusterdeployment.Build(clusterDeploymentBase()),
testclusterdeployment.Build(clusterDeploymentBase(), testclusterdeployment.Generic(generic.WithNamespace("not the correct namespace"))),
testclusterdeployment.Build(clusterDeploymentBase(), testclusterdeployment.Generic(generic.WithNamespace("not the correct namespace")), testclusterdeployment.WithResourceVersion("999")),
},
expectedObjects: []runtime.Object{
testclusterdeployment.Build(clusterDeploymentBase()),
testclusterdeployment.Build(clusterDeploymentBase(), testclusterdeployment.WithResourceVersion("999")),
},
},
}
Expand Down Expand Up @@ -383,7 +383,7 @@ func TestGetNamespaceCheckpoint(t *testing.T) {
name: "Existing Checkpoint",
expectedFound: true,
existingObjects: []runtime.Object{testcheckpoint.Build(checkpointBase(), testcheckpoint.WithLastBackupChecksum("NOTREAL"))},
expectedCheckpoint: testcheckpoint.Build(checkpointBase(), testcheckpoint.WithLastBackupChecksum("NOTREAL"), testcheckpoint.WithTypeMeta()),
expectedCheckpoint: testcheckpoint.Build(checkpointBase(), testcheckpoint.WithLastBackupChecksum("NOTREAL"), testcheckpoint.WithTypeMeta(), testcheckpoint.WithResourceVersion("999")),
expectedError: nil,
},
}
Expand Down Expand Up @@ -441,7 +441,7 @@ func TestCreateOrUpdateNamespaceCheckpoint(t *testing.T) {
existingObjects: []runtime.Object{
testcheckpoint.Build(checkpointBase(), testcheckpoint.WithLastBackupChecksum("NOTREAL-BEFORE")),
},
expectedCheckpoint: testcheckpoint.Build(checkpointBase(), testcheckpoint.WithLastBackupChecksum("NOTREAL-BEFORE"), testcheckpoint.WithTypeMeta()),
expectedCheckpoint: testcheckpoint.Build(checkpointBase(), testcheckpoint.WithLastBackupChecksum("NOTREAL-BEFORE"), testcheckpoint.WithTypeMeta(), testcheckpoint.WithResourceVersion("999")),
expectedError: statusErr,
},
{
Expand Down Expand Up @@ -480,7 +480,7 @@ func TestCalculateObjectsChecksumWithoutStatus(t *testing.T) {
}{
{
name: "Valid ClusterDeployment Checksum",
object: testclusterdeployment.Build(clusterDeploymentBase()),
object: testclusterdeployment.Build(clusterDeploymentBase(), testclusterdeployment.WithResourceVersion("999")),
expectedChecksum: calculateClusterDeploymentChecksum(testclusterdeployment.Build(clusterDeploymentBase())),
},
{
Expand Down
5 changes: 5 additions & 0 deletions pkg/test/clusterdeployment/clusterdeployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ func WithName(name string) Option {
return Generic(generic.WithName(name))
}

// WithResourceVersion sets the specified resource version on the supplied object.
func WithResourceVersion(resourceVersion string) Option {
return Generic(generic.WithResourceVersion(resourceVersion))
}

// WithNamespace sets the object.Namespace field when building an object with Build.
func WithNamespace(namespace string) Option {
return Generic(generic.WithNamespace(namespace))
Expand Down
5 changes: 5 additions & 0 deletions pkg/test/syncset/syncset.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,8 @@ func WithPatches(patches ...hivev1.SyncObjectPatch) Option {
syncSet.Spec.Patches = patches
}
}

// WithResourceVersion sets the specified resource version on the supplied object.
func WithResourceVersion(resourceVersion string) Option {
return Generic(generic.WithResourceVersion(resourceVersion))
}

0 comments on commit c7d6052

Please sign in to comment.