forked from openstack-k8s-operators/openstack-operator
-
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.
- Loading branch information
Showing
6 changed files
with
320 additions
and
6 deletions.
There are no files selected for viewing
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
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
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
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,52 @@ | ||
/* | ||
Copyright 2023. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package functional_test | ||
|
||
import ( | ||
. "github.com/onsi/gomega" | ||
|
||
"k8s.io/apimachinery/pkg/types" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
|
||
openstackclientv1 "github.com/openstack-k8s-operators/openstack-operator/apis/client/v1beta1" | ||
) | ||
|
||
func GetDefaultOpenStackClientSpec() map[string]interface{} { | ||
return map[string]interface{}{} | ||
} | ||
|
||
func CreateOpenStackClient(name types.NamespacedName, spec map[string]interface{}) client.Object { | ||
|
||
raw := map[string]interface{}{ | ||
"apiVersion": "client.openstack.org/v1beta1", | ||
"kind": "OpenStackClient", | ||
"metadata": map[string]interface{}{ | ||
"name": name.Name, | ||
"namespace": name.Namespace, | ||
}, | ||
"spec": spec, | ||
} | ||
return th.CreateUnstructured(raw) | ||
} | ||
|
||
func GetOpenStackClient(name types.NamespacedName) *openstackclientv1.OpenStackClient { | ||
instance := &openstackclientv1.OpenStackClient{} | ||
Eventually(func(g Gomega) { | ||
g.Expect(k8sClient.Get(ctx, name, instance)).Should(Succeed()) | ||
}, timeout, interval).Should(Succeed()) | ||
return instance | ||
} |
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,71 @@ | ||
/* | ||
Copyright 2023. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package functional_test | ||
|
||
import ( | ||
"os" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"k8s.io/apimachinery/pkg/types" | ||
|
||
openstackclientv1 "github.com/openstack-k8s-operators/openstack-operator/apis/client/v1beta1" | ||
) | ||
|
||
var _ = Describe("OpenStackClient Webhook", func() { | ||
|
||
var openstackclientName types.NamespacedName | ||
|
||
BeforeEach(func() { | ||
|
||
openstackclientName = types.NamespacedName{ | ||
Name: "foo", | ||
Namespace: namespace, | ||
} | ||
|
||
err := os.Setenv("OPERATOR_TEMPLATES", "../../templates") | ||
Expect(err).NotTo(HaveOccurred()) | ||
}) | ||
|
||
When("A OpenStackClient instance is created without container images", func() { | ||
BeforeEach(func() { | ||
DeferCleanup(th.DeleteInstance, CreateOpenStackClient(openstackclientName, GetDefaultOpenStackClientSpec())) | ||
}) | ||
|
||
It("should have the defaults initialized by webhook", func() { | ||
OpenStackClient := GetOpenStackClient(openstackclientName) | ||
Expect(OpenStackClient.Spec.ContainerImage).Should(Equal( | ||
openstackclientv1.OpenStackClientContainerImage, | ||
)) | ||
}) | ||
}) | ||
|
||
When("A OpenStackClient instance is created with container images", func() { | ||
BeforeEach(func() { | ||
openstackclientSpec := GetDefaultOpenStackClientSpec() | ||
openstackclientSpec["containerImage"] = "api-container-image" | ||
DeferCleanup(th.DeleteInstance, CreateOpenStackClient(openstackclientName, openstackclientSpec)) | ||
}) | ||
|
||
It("should use the given values", func() { | ||
OpenStackClient := GetOpenStackClient(openstackclientName) | ||
Expect(OpenStackClient.Spec.ContainerImage).Should(Equal( | ||
"api-container-image", | ||
)) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.