Skip to content

Commit

Permalink
fix: Update ModuleTemplate's Metadata name (#82)
Browse files Browse the repository at this point in the history
* update metadata name ending to version

* adjust e2e test accordingly

* fix import

* improve tests
  • Loading branch information
amritanshusikdar authored Oct 29, 2024
1 parent a654e4d commit 7d1a91d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
2 changes: 1 addition & 1 deletion internal/service/templategenerator/templategenerator.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func (s *Service) GenerateModuleTemplate(
shortName := trimShortNameFromRef(ref)
labels[shared.ModuleName] = shortName
if moduleConfig.ResourceName == "" {
moduleConfig.ResourceName = shortName + "-" + moduleConfig.Channel
moduleConfig.ResourceName = shortName + "-" + moduleConfig.Version
}

moduleTemplate, err := template.New("moduleTemplate").Funcs(template.FuncMap{
Expand Down
23 changes: 19 additions & 4 deletions tests/e2e/create/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"ocm.software/ocm/api/ocm"
"ocm.software/ocm/api/ocm/compdesc"
ocmv1 "ocm.software/ocm/api/ocm/compdesc/meta/v1"
"ocm.software/ocm/api/ocm/compdesc/versions/v2"
v2 "ocm.software/ocm/api/ocm/compdesc/versions/v2"
"ocm.software/ocm/api/ocm/extensions/accessmethods/github"
"ocm.software/ocm/api/ocm/extensions/accessmethods/localblob"
"ocm.software/ocm/api/ocm/extensions/accessmethods/ociartifact"
Expand Down Expand Up @@ -218,6 +218,8 @@ var _ = Describe("Test 'create' command", Ordered, func() {
Expect(descriptor).ToNot(BeNil())
Expect(descriptor.SchemaVersion()).To(Equal(v2.SchemaVersion))

Expect(template.Name).To(Equal("template-operator-1.0.0"))

By("And annotations should be correct")
annotations := template.Annotations
Expect(annotations[shared.ModuleVersionAnnotation]).To(Equal("1.0.0"))
Expand Down Expand Up @@ -303,6 +305,8 @@ var _ = Describe("Test 'create' command", Ordered, func() {
descriptor := getDescriptor(template)
Expect(descriptor).ToNot(BeNil())

Expect(template.Name).To(Equal("template-operator-1.0.1"))

By("And new annotation should be correctly added")
annotations := template.Annotations
Expect(annotations[shared.ModuleVersionAnnotation]).To(Equal("1.0.1"))
Expand Down Expand Up @@ -337,6 +341,8 @@ var _ = Describe("Test 'create' command", Ordered, func() {
descriptor := getDescriptor(template)
Expect(descriptor).ToNot(BeNil())

Expect(template.Name).To(Equal("template-operator-1.0.2"))

By("And annotation should have correct version")
annotations := template.Annotations
Expect(annotations[shared.ModuleVersionAnnotation]).To(Equal("1.0.2"))
Expand Down Expand Up @@ -384,6 +390,8 @@ var _ = Describe("Test 'create' command", Ordered, func() {
descriptor := getDescriptor(template)
Expect(descriptor).ToNot(BeNil())

Expect(template.Name).To(Equal("template-operator-1.0.3"))

By("And descriptor.component.resources should be correct")
Expect(descriptor.Resources).To(HaveLen(2))
resource := descriptor.Resources[0]
Expand Down Expand Up @@ -459,6 +467,8 @@ var _ = Describe("Test 'create' command", Ordered, func() {
descriptor := getDescriptor(template)
Expect(descriptor).ToNot(BeNil())

Expect(template.Name).To(Equal("template-operator-1.0.4"))

By("And annotation should have correct version")
annotations := template.Annotations
Expect(annotations[shared.ModuleVersionAnnotation]).To(Equal("1.0.4"))
Expand Down Expand Up @@ -490,6 +500,8 @@ var _ = Describe("Test 'create' command", Ordered, func() {
descriptor := getDescriptor(template)
Expect(descriptor).ToNot(BeNil())

Expect(template.Name).To(Equal("template-operator-1.0.5"))

By("And annotation should have correct version")
annotations := template.Annotations
Expect(annotations[shared.ModuleVersionAnnotation]).To(Equal("1.0.5"))
Expand Down Expand Up @@ -528,6 +540,8 @@ var _ = Describe("Test 'create' command", Ordered, func() {
descriptor := getDescriptor(template)
Expect(descriptor).ToNot(BeNil())

Expect(template.Name).To(Equal("template-operator-1.0.6"))

By("And annotation should have correct version")
annotations := template.Annotations
Expect(annotations[shared.ModuleVersionAnnotation]).To(Equal("1.0.6"))
Expand All @@ -542,14 +556,13 @@ var _ = Describe("Test 'create' command", Ordered, func() {
Expect(manager.Kind).To(Equal("Deployment"))
})
})



Context("Given 'modulectl create' command", func() {
var cmd createCmd
It("When invoked with valid module-config containing associatedResources list", func() {
cmd = createCmd{
moduleConfigFile: withAssociatedResourcesConfig,
registry: ociRegistry,
registry: ociRegistry,
insecure: true,
output: templateOutputPath,
}
Expand All @@ -566,6 +579,8 @@ var _ = Describe("Test 'create' command", Ordered, func() {
descriptor := getDescriptor(template)
Expect(descriptor).ToNot(BeNil())

Expect(template.Name).To(Equal("template-operator-1.0.7"))

By("And annotation should have correct version")
annotations := template.Annotations
Expect(annotations[shared.ModuleVersionAnnotation]).To(Equal("1.0.7"))
Expand Down

0 comments on commit 7d1a91d

Please sign in to comment.