forked from konflux-ci/integration-service
-
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.
feat(HACBS-805): Add unit testing for helper functions
- Loading branch information
1 parent
2371449
commit c46670b
Showing
2 changed files
with
136 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package helpers_test | ||
|
||
import ( | ||
"testing" | ||
|
||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
) | ||
|
||
func TestHelpers(t *testing.T) { | ||
RegisterFailHandler(Fail) | ||
RunSpecs(t, "Helpers 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,123 @@ | ||
package helpers_test | ||
|
||
import ( | ||
. "github.com/onsi/ginkgo/v2" | ||
. "github.com/onsi/gomega" | ||
"github.com/redhat-appstudio/integration-service/helpers" | ||
|
||
tektonv1beta1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1beta1" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
var _ = Describe("Helpers for labels and annotation", Ordered, func() { | ||
|
||
var ( | ||
testpipelineLabel *tektonv1beta1.PipelineRun | ||
) | ||
|
||
BeforeEach(func() { | ||
testpipelineLabel = &tektonv1beta1.PipelineRun{ | ||
ObjectMeta: v1.ObjectMeta{ | ||
GenerateName: "testpipelineLabel-", | ||
Namespace: "default", | ||
}, | ||
} | ||
Expect(testpipelineLabel).NotTo(BeNil()) | ||
}) | ||
|
||
Context("testing integration service helpers to validate Labels and its value", func() { | ||
It("HasLabel with an existing label and return true", func() { | ||
testpipelineLabel.ObjectMeta.Labels = map[string]string{ | ||
"pipelines.appstudio.openshift.io/type": "test", | ||
} | ||
Expect(testpipelineLabel.ObjectMeta.Labels["pipelines.appstudio.openshift.io/type"]). | ||
Should(Equal("test")) | ||
Expect(helpers.HasLabel(testpipelineLabel, "pipelines.appstudio.openshift.io/type")). | ||
To(BeTrue()) | ||
}) | ||
It("HasLabel with an non-existent label and return false", func() { | ||
testpipelineLabel.ObjectMeta.Labels = map[string]string{ | ||
"pipelines.appstudio.openshift.io/type": "test", | ||
} | ||
Expect(testpipelineLabel.ObjectMeta.Labels["pipelines.appstudio.openshift.io/not-exist"]). | ||
To(Equal("")) | ||
Expect(helpers.HasLabel(testpipelineLabel, "pipelines.appstudio.openshift.io/not-exist")). | ||
To(BeFalse()) | ||
}) | ||
It("HasLabelvalue with an existing label value and return true", func() { | ||
testpipelineLabel.ObjectMeta.Labels = map[string]string{ | ||
"pipelines.appstudio.openshift.io/type": "test", | ||
"PipelinesTypeLabel": "integration", | ||
} | ||
Expect(testpipelineLabel.ObjectMeta.Labels["PipelinesTypeLabel"]). | ||
To(Equal("integration")) | ||
Expect(helpers.HasLabelWithValue(testpipelineLabel, "PipelinesTypeLabel", "integration")). | ||
To(BeTrue()) | ||
}) | ||
It("HasLabelvalue with an different label value and return false", func() { | ||
testpipelineLabel.ObjectMeta.Labels = map[string]string{ | ||
"pipelines.appstudio.openshift.io/type": "test", | ||
"PipelinesTypeLabel": "integration", | ||
} | ||
Expect(testpipelineLabel.ObjectMeta.Labels["NoLabel"]). | ||
To(Equal("")) | ||
Expect(helpers.HasLabelWithValue(testpipelineLabel, "NoLabel", "integration")). | ||
To(BeFalse()) | ||
}) | ||
It("HasLabelvalue with an No label value and return false", func() { | ||
testpipelineLabel.ObjectMeta.Labels = map[string]string{ | ||
"pipelines.appstudio.openshift.io/type": "test", | ||
"PipelinesTypeLabel": "integration", | ||
} | ||
Expect(testpipelineLabel.ObjectMeta.Labels[""]). | ||
To(Equal("")) | ||
Expect(helpers.HasLabelWithValue(testpipelineLabel, "", "integration")). | ||
To(BeFalse()) | ||
}) | ||
It("HasAnnotation with an existing Annotation and return true", func() { | ||
testpipelineLabel.ObjectMeta.Annotations = map[string]string{ | ||
"AnnotationKey": "integration", | ||
} | ||
Expect(testpipelineLabel.ObjectMeta.Annotations["AnnotationKey"]). | ||
Should(Equal("integration")) | ||
Expect(helpers.HasAnnotation(testpipelineLabel, "AnnotationKey")). | ||
To(BeTrue()) | ||
}) | ||
It("HasAnnotation with an Different Annotation and return false", func() { | ||
testpipelineLabel.ObjectMeta.Annotations = map[string]string{ | ||
"AnnotationKey": "integration", | ||
} | ||
Expect(testpipelineLabel.ObjectMeta.Annotations["NoAnnotationKey"]). | ||
Should(Equal("")) | ||
Expect(helpers.HasAnnotation(testpipelineLabel, "NoAnnotationKey")). | ||
To(BeFalse()) | ||
}) | ||
It("HasAnnotationValue with an existing Annotation and return true", func() { | ||
testpipelineLabel.ObjectMeta.Annotations = map[string]string{ | ||
"AnnotationKey": "integration", | ||
} | ||
Expect(testpipelineLabel.ObjectMeta.Annotations["AnnotationKey"]). | ||
Should(Equal("integration")) | ||
Expect(helpers.HasAnnotationWithValue(testpipelineLabel, "AnnotationKey", "integration")). | ||
To(BeTrue()) | ||
}) | ||
It("HasAnnotation with an Different Annotation and return false", func() { | ||
testpipelineLabel.ObjectMeta.Annotations = map[string]string{ | ||
"AnnotationKey": "integration", | ||
} | ||
Expect(testpipelineLabel.ObjectMeta.Annotations["NoAnnotationKey"]). | ||
Should(Equal("")) | ||
Expect(helpers.HasAnnotationWithValue(testpipelineLabel, "NoAnnotationKey", "integration")). | ||
To(BeFalse()) | ||
}) | ||
It("HasAnnotation with an No Annotation and return false", func() { | ||
testpipelineLabel.ObjectMeta.Annotations = map[string]string{ | ||
"AnnotationKey": "integration", | ||
} | ||
Expect(testpipelineLabel.ObjectMeta.Annotations[""]). | ||
Should(Equal("")) | ||
Expect(helpers.HasAnnotationWithValue(testpipelineLabel, "", "integration")). | ||
To(BeFalse()) | ||
}) | ||
}) | ||
}) |