Skip to content

Commit

Permalink
fix(metrics-operator): introduce IsStatusSet method to KeptnMetric (#…
Browse files Browse the repository at this point in the history
…1427)

Signed-off-by: odubajDT <ondrej.dubaj@dynatrace.com>
  • Loading branch information
odubajDT committed May 17, 2023
1 parent daedf87 commit 24a60f5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
4 changes: 4 additions & 0 deletions metrics-operator/api/v1alpha3/keptnmetric_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,7 @@ type KeptnMetricList struct {
func init() {
SchemeBuilder.Register(&KeptnMetric{}, &KeptnMetricList{})
}

func (s *KeptnMetric) IsStatusSet() bool {
return s.Status.Value != ""
}
53 changes: 53 additions & 0 deletions metrics-operator/api/v1alpha3/keptnmetric_types_test.go
Original file line number Diff line number Diff line change
@@ -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)
}
})
}
}

0 comments on commit 24a60f5

Please sign in to comment.