From 24a60f5e6f8f3a383dfce554d644bfd974c4b5fd Mon Sep 17 00:00:00 2001 From: odubajDT <93584209+odubajDT@users.noreply.github.com> Date: Wed, 17 May 2023 15:49:32 +0200 Subject: [PATCH] fix(metrics-operator): introduce IsStatusSet method to KeptnMetric (#1427) Signed-off-by: odubajDT --- .../api/v1alpha3/keptnmetric_types.go | 4 ++ .../api/v1alpha3/keptnmetric_types_test.go | 53 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 metrics-operator/api/v1alpha3/keptnmetric_types_test.go diff --git a/metrics-operator/api/v1alpha3/keptnmetric_types.go b/metrics-operator/api/v1alpha3/keptnmetric_types.go index d4781566ec..5b4e507609 100644 --- a/metrics-operator/api/v1alpha3/keptnmetric_types.go +++ b/metrics-operator/api/v1alpha3/keptnmetric_types.go @@ -79,3 +79,7 @@ type KeptnMetricList struct { func init() { SchemeBuilder.Register(&KeptnMetric{}, &KeptnMetricList{}) } + +func (s *KeptnMetric) IsStatusSet() bool { + return s.Status.Value != "" +} diff --git a/metrics-operator/api/v1alpha3/keptnmetric_types_test.go b/metrics-operator/api/v1alpha3/keptnmetric_types_test.go new file mode 100644 index 0000000000..a7700f4017 --- /dev/null +++ b/metrics-operator/api/v1alpha3/keptnmetric_types_test.go @@ -0,0 +1,53 @@ +package v1alpha3 + +import ( + "testing" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func TestKeptnMetric_IsStatusSet(t *testing.T) { + type fields struct { + TypeMeta v1.TypeMeta + ObjectMeta v1.ObjectMeta + Spec KeptnMetricSpec + Status KeptnMetricStatus + } + tests := []struct { + name string + fields fields + want bool + }{ + { + name: "No value set", + fields: fields{ + Status: KeptnMetricStatus{ + Value: "", + }, + }, + want: false, + }, + { + name: "we have a value", + fields: fields{ + Status: KeptnMetricStatus{ + Value: "1.0", + }, + }, + want: true, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + s := &KeptnMetric{ + TypeMeta: tt.fields.TypeMeta, + ObjectMeta: tt.fields.ObjectMeta, + Spec: tt.fields.Spec, + Status: tt.fields.Status, + } + if got := s.IsStatusSet(); got != tt.want { + t.Errorf("IsStatusSet() = %v, want %v", got, tt.want) + } + }) + } +}