forked from openstack-k8s-operators/watcher-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.
Add functional test to validate samples
This patch is adding a functional test to validate the Watcher sample. This test whould have uncovered the previous issue with samples. Note that this is only validating the Watcher CRD sample. For the rest, we will add it while creating the basic structrue for each one.
- Loading branch information
1 parent
0423b15
commit 46968a0
Showing
2 changed files
with
66 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
Copyright 2024. | ||
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 | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
|
||
. "github.com/onsi/ginkgo/v2" //revive:disable:dot-imports | ||
. "github.com/onsi/gomega" //revive:disable:dot-imports | ||
"gopkg.in/yaml.v3" | ||
"k8s.io/apimachinery/pkg/types" | ||
) | ||
|
||
const SamplesDir = "../../config/samples/" | ||
|
||
func ReadSample(sampleFileName string) map[string]interface{} { | ||
rawSample := make(map[string]interface{}) | ||
|
||
bytes, err := os.ReadFile(filepath.Join(SamplesDir, sampleFileName)) | ||
Expect(err).ShouldNot(HaveOccurred()) | ||
Expect(yaml.Unmarshal(bytes, rawSample)).Should(Succeed()) | ||
|
||
return rawSample | ||
} | ||
|
||
// TODO(amoralej) This is creating the test to validate Watcher sample. | ||
// For the rest of CRs we will add additional tests when creating the basic structure | ||
// and envtest. | ||
|
||
func CreateWatcherFromSample(sampleFileName string, name types.NamespacedName) types.NamespacedName { | ||
raw := ReadSample(sampleFileName) | ||
instance := CreateWatcher(name, raw["spec"].(map[string]interface{})) | ||
DeferCleanup(th.DeleteInstance, instance) | ||
return types.NamespacedName{Name: instance.GetName(), Namespace: instance.GetNamespace()} | ||
} | ||
|
||
// This is a set of test for our samples. It only validates that the sample | ||
// file has all the required field with proper types. But it does not | ||
// validate that using a sample file will result in a working deployment. | ||
// TODO(gibi): By building up all the prerequisites (e.g. MariaDBDatabase) in | ||
// the test and by simulating Job and Deployment success we could assert | ||
// that each sample creates a CR in Ready state. | ||
var _ = Describe("Samples", func() { | ||
|
||
When("watcher_v1beta1_watcher.yaml sample is applied", func() { | ||
It("Watcher is created", func() { | ||
name := CreateWatcherFromSample("watcher_v1beta1_watcher.yaml", watcherTest.Instance) | ||
GetWatcher(name) | ||
}) | ||
}) | ||
}) |