forked from kubevirt/kubevirt
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubevirt#13823 from ksimon1/annotations
feat: move instance types annotations unit tests to correct packages
- Loading branch information
Showing
9 changed files
with
172 additions
and
94 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package annotations_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestAnnotations(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Annotations Suite") | ||
} |
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,55 @@ | ||
package annotations_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
v1 "kubevirt.io/api/core/v1" | ||
apiinstancetype "kubevirt.io/api/instancetype" | ||
|
||
"kubevirt.io/kubevirt/pkg/instancetype/annotations" | ||
"kubevirt.io/kubevirt/pkg/libvmi" | ||
) | ||
|
||
var _ = Describe("Annotations", func() { | ||
var ( | ||
vm *v1.VirtualMachine | ||
meta *metav1.ObjectMeta | ||
) | ||
|
||
const instancetypeName = "instancetype-name" | ||
|
||
BeforeEach(func() { | ||
vm = libvmi.NewVirtualMachine(libvmi.New(), libvmi.WithInstancetype(instancetypeName)) | ||
|
||
meta = &metav1.ObjectMeta{} | ||
}) | ||
|
||
It("should add instancetype name annotation", func() { | ||
vm.Spec.Instancetype.Kind = apiinstancetype.SingularResourceName | ||
|
||
annotations.Set(vm, meta) | ||
|
||
Expect(meta.Annotations).To(HaveKeyWithValue(v1.InstancetypeAnnotation, instancetypeName)) | ||
Expect(meta.Annotations).ToNot(HaveKey(v1.ClusterInstancetypeAnnotation)) | ||
}) | ||
|
||
It("should add cluster instancetype name annotation", func() { | ||
vm.Spec.Instancetype.Kind = apiinstancetype.ClusterSingularResourceName | ||
|
||
annotations.Set(vm, meta) | ||
|
||
Expect(meta.Annotations).ToNot(HaveKey(v1.InstancetypeAnnotation)) | ||
Expect(meta.Annotations).To(HaveKeyWithValue(v1.ClusterInstancetypeAnnotation, instancetypeName)) | ||
}) | ||
|
||
It("should add cluster name annotation, if instancetype.kind is empty", func() { | ||
vm.Spec.Instancetype.Kind = "" | ||
|
||
annotations.Set(vm, meta) | ||
|
||
Expect(meta.Annotations).ToNot(HaveKey(v1.InstancetypeAnnotation)) | ||
Expect(meta.Annotations).To(HaveKeyWithValue(v1.ClusterInstancetypeAnnotation, instancetypeName)) | ||
}) | ||
}) |
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
13 changes: 13 additions & 0 deletions
13
pkg/instancetype/preference/annotations/annotations_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,13 @@ | ||
package annotations_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestAnnotations(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Annotations Suite") | ||
} |
55 changes: 55 additions & 0 deletions
55
pkg/instancetype/preference/annotations/annotations_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,55 @@ | ||
package annotations_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
|
||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
v1 "kubevirt.io/api/core/v1" | ||
apiinstancetype "kubevirt.io/api/instancetype" | ||
|
||
"kubevirt.io/kubevirt/pkg/instancetype/preference/annotations" | ||
"kubevirt.io/kubevirt/pkg/libvmi" | ||
) | ||
|
||
var _ = Describe("Preferences - annotations", func() { | ||
var ( | ||
vm *v1.VirtualMachine | ||
meta *metav1.ObjectMeta | ||
) | ||
|
||
const preferenceName = "preference-name" | ||
|
||
BeforeEach(func() { | ||
vm = libvmi.NewVirtualMachine(libvmi.New(), libvmi.WithPreference(preferenceName)) | ||
|
||
meta = &metav1.ObjectMeta{} | ||
}) | ||
|
||
It("should add preference name annotation", func() { | ||
vm.Spec.Preference.Kind = apiinstancetype.SingularPreferenceResourceName | ||
|
||
annotations.Set(vm, meta) | ||
|
||
Expect(meta.Annotations).To(HaveKeyWithValue(v1.PreferenceAnnotation, preferenceName)) | ||
Expect(meta.Annotations).ToNot(HaveKey(v1.ClusterPreferenceAnnotation)) | ||
}) | ||
|
||
It("should add cluster preference name annotation", func() { | ||
vm.Spec.Preference.Kind = apiinstancetype.ClusterSingularPreferenceResourceName | ||
|
||
annotations.Set(vm, meta) | ||
|
||
Expect(meta.Annotations).ToNot(HaveKey(v1.PreferenceAnnotation)) | ||
Expect(meta.Annotations).To(HaveKeyWithValue(v1.ClusterPreferenceAnnotation, preferenceName)) | ||
}) | ||
|
||
It("should add cluster name annotation, if preference.kind is empty", func() { | ||
vm.Spec.Preference.Kind = "" | ||
|
||
annotations.Set(vm, meta) | ||
|
||
Expect(meta.Annotations).ToNot(HaveKey(v1.PreferenceAnnotation)) | ||
Expect(meta.Annotations).To(HaveKeyWithValue(v1.ClusterPreferenceAnnotation, preferenceName)) | ||
}) | ||
}) |