This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: move customimage unit tests to their own package
- Loading branch information
Showing
5 changed files
with
173 additions
and
150 deletions.
There are no files selected for viewing
77 changes: 77 additions & 0 deletions
77
pkg/handlers/docker/mutation/customimage/inject_control_plane_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
// Copyright 2023 D2iQ, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package customimage | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
"github.com/onsi/gomega" | ||
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" | ||
|
||
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation" | ||
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest" | ||
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request" | ||
dockerclusterconfig "github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/clusterconfig" | ||
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/clusterconfig" | ||
) | ||
|
||
var _ = Describe("Docker CustomImage patches for ControlPlane", func() { | ||
patchGenerator := func() mutation.GeneratePatches { | ||
return mutation.NewMetaGeneratePatchesHandler("", NewControlPlanePatch()).(mutation.GeneratePatches) | ||
} | ||
|
||
testDefs := []capitest.PatchTestDef{ | ||
{ | ||
Name: "image unset for control plane", | ||
Vars: []runtimehooksv1.Variable{ | ||
capitest.VariableWithValue( | ||
"builtin", | ||
apiextensionsv1.JSON{Raw: []byte(`{"controlPlane": {"version": "v1.2.3"}}`)}, | ||
), | ||
}, | ||
RequestItem: request.NewCPDockerMachineTemplateRequestItem("1234"), | ||
ExpectedPatchMatchers: []capitest.JSONPatchMatcher{{ | ||
Operation: "add", | ||
Path: "/spec/template/spec/customImage", | ||
ValueMatcher: gomega.Equal("ghcr.io/mesosphere/kind-node:v1.2.3"), | ||
}}, | ||
}, | ||
{ | ||
Name: "image set for control plane", | ||
Vars: []runtimehooksv1.Variable{ | ||
capitest.VariableWithValue( | ||
clusterconfig.MetaVariableName, | ||
"a-specific-image", | ||
clusterconfig.MetaControlPlaneConfigName, | ||
dockerclusterconfig.DockerVariableName, | ||
VariableName, | ||
), | ||
capitest.VariableWithValue( | ||
"builtin", | ||
apiextensionsv1.JSON{ | ||
Raw: []byte(`{"machineDeployment": {"class": "a-worker"}}`), | ||
}, | ||
), | ||
}, | ||
RequestItem: request.NewCPDockerMachineTemplateRequestItem("1234"), | ||
ExpectedPatchMatchers: []capitest.JSONPatchMatcher{{ | ||
Operation: "add", | ||
Path: "/spec/template/spec/customImage", | ||
ValueMatcher: gomega.Equal("a-specific-image"), | ||
}}, | ||
}, | ||
} | ||
|
||
// create test node for each case | ||
for testIdx := range testDefs { | ||
tt := testDefs[testIdx] | ||
It(tt.Name, func() { | ||
capitest.AssertGeneratePatches( | ||
GinkgoT(), | ||
patchGenerator, | ||
&tt, | ||
) | ||
}) | ||
} | ||
}) |
16 changes: 16 additions & 0 deletions
16
pkg/handlers/docker/mutation/customimage/inject_suite_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Copyright 2023 D2iQ, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package customimage | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestCustomImagePatch(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Docker CustomImage patches for ControlPlane and Workers suite") | ||
} |
80 changes: 80 additions & 0 deletions
80
pkg/handlers/docker/mutation/customimage/inject_worker_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
// Copyright 2023 D2iQ, Inc. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package customimage | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
"github.com/onsi/gomega" | ||
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
runtimehooksv1 "sigs.k8s.io/cluster-api/exp/runtime/hooks/api/v1alpha1" | ||
|
||
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/capi/clustertopology/handlers/mutation" | ||
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest" | ||
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/common/pkg/testutils/capitest/request" | ||
dockerworkerconfig "github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/pkg/handlers/docker/workerconfig" | ||
"github.com/d2iq-labs/cluster-api-runtime-extensions-nutanix/pkg/handlers/generic/workerconfig" | ||
) | ||
|
||
var _ = Describe("Docker CustomImage patches for workers", func() { | ||
patchGenerator := func() mutation.GeneratePatches { | ||
return mutation.NewMetaGeneratePatchesHandler("", NewWorkerPatch()).(mutation.GeneratePatches) | ||
} | ||
|
||
testDefs := []capitest.PatchTestDef{ | ||
{ | ||
Name: "image unset for workers", | ||
Vars: []runtimehooksv1.Variable{ | ||
capitest.VariableWithValue( | ||
"builtin", | ||
apiextensionsv1.JSON{ | ||
Raw: []byte( | ||
`{"machineDeployment": {"class": "a-worker", "version": "v1.2.3"}}`, | ||
), | ||
}, | ||
), | ||
}, | ||
RequestItem: request.NewWorkerDockerMachineTemplateRequestItem("1234"), | ||
ExpectedPatchMatchers: []capitest.JSONPatchMatcher{{ | ||
Operation: "add", | ||
Path: "/spec/template/spec/customImage", | ||
ValueMatcher: gomega.Equal("ghcr.io/mesosphere/kind-node:v1.2.3"), | ||
}}, | ||
}, | ||
{ | ||
Name: "image set for workers", | ||
Vars: []runtimehooksv1.Variable{ | ||
capitest.VariableWithValue( | ||
workerconfig.MetaVariableName, | ||
"a-specific-image", | ||
dockerworkerconfig.DockerVariableName, | ||
VariableName, | ||
), | ||
capitest.VariableWithValue( | ||
"builtin", | ||
apiextensionsv1.JSON{ | ||
Raw: []byte(`{"machineDeployment": {"class": "a-worker"}}`), | ||
}, | ||
), | ||
}, | ||
RequestItem: request.NewWorkerDockerMachineTemplateRequestItem("1234"), | ||
ExpectedPatchMatchers: []capitest.JSONPatchMatcher{{ | ||
Operation: "add", | ||
Path: "/spec/template/spec/customImage", | ||
ValueMatcher: gomega.Equal("a-specific-image"), | ||
}}, | ||
}, | ||
} | ||
|
||
// create test node for each case | ||
for testIdx := range testDefs { | ||
tt := testDefs[testIdx] | ||
It(tt.Name, func() { | ||
capitest.AssertGeneratePatches( | ||
GinkgoT(), | ||
patchGenerator, | ||
&tt, | ||
) | ||
}) | ||
} | ||
}) |
122 changes: 0 additions & 122 deletions
122
pkg/handlers/docker/mutation/customimage/tests/generate_patches.go
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters