|
| 1 | +/* |
| 2 | +Copyright 2022. |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +*/ |
| 16 | + |
| 17 | +package v1beta1 |
| 18 | + |
| 19 | +import ( |
| 20 | + . "github.com/onsi/ginkgo/v2" |
| 21 | + . "github.com/onsi/gomega" |
| 22 | + "testing" |
| 23 | +) |
| 24 | + |
| 25 | +func TestV1beta1(t *testing.T) { |
| 26 | + RegisterFailHandler(Fail) |
| 27 | + RunSpecs(t, "V1beta1 Suite") |
| 28 | +} |
| 29 | + |
| 30 | +var validKMs = []KernelMapping{ |
| 31 | + {Regexp: "valid-regex"}, |
| 32 | +} |
| 33 | + |
| 34 | +var invalidKMs = []KernelMapping{ |
| 35 | + {Regexp: "*-invalid-regex"}, |
| 36 | +} |
| 37 | + |
| 38 | +var module = &Module{ |
| 39 | + Spec: ModuleSpec{ |
| 40 | + ModuleLoader: ModuleLoaderSpec{ |
| 41 | + Container: ModuleLoaderContainerSpec{ |
| 42 | + KernelMappings: nil, |
| 43 | + }, |
| 44 | + }, |
| 45 | + }, |
| 46 | +} |
| 47 | + |
| 48 | +var _ = BeforeEach(func() { |
| 49 | + module.Spec.ModuleLoader.Container.KernelMappings = validKMs |
| 50 | +}) |
| 51 | + |
| 52 | +var _ = Describe("ValidateCreate", func() { |
| 53 | + It("should pass when all conditions are met", func() { |
| 54 | + e := module.ValidateCreate() |
| 55 | + Expect(e).To(BeNil()) |
| 56 | + }) |
| 57 | + |
| 58 | + It("should fail when an invalid regex is found", func() { |
| 59 | + m := module |
| 60 | + m.Spec.ModuleLoader.Container.KernelMappings = invalidKMs |
| 61 | + e := module.ValidateCreate() |
| 62 | + Expect(e).To(HaveOccurred()) |
| 63 | + Expect(e.Error()).To(ContainSubstring("invalid regex:")) |
| 64 | + }) |
| 65 | +}) |
| 66 | + |
| 67 | +var _ = Describe("ValidateUpdate", func() { |
| 68 | + It("should pass when all conditions are met", func() { |
| 69 | + e := module.ValidateUpdate(nil) |
| 70 | + Expect(e).To(BeNil()) |
| 71 | + }) |
| 72 | +}) |
| 73 | + |
| 74 | +var _ = Describe("ValidateDelete", func() { |
| 75 | + It("should do nothing and return always nil", func() { |
| 76 | + e := module.ValidateDelete() |
| 77 | + Expect(e).To(BeNil()) |
| 78 | + }) |
| 79 | +}) |
0 commit comments