-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(operator): refactor existing interfaces (#419)
Signed-off-by: odubajDT <[email protected]>
- Loading branch information
Showing
24 changed files
with
827 additions
and
254 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
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
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,33 @@ | ||
package common | ||
|
||
import ( | ||
"go.opentelemetry.io/otel/attribute" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
) | ||
|
||
//go:generate moq -pkg fake --skip-ensure -out ./fake/activemetricsobject_mock.go . ActiveMetricsObject | ||
//ActiveMetricsObject represents an object whose active metrics are stored | ||
type ActiveMetricsObject interface { | ||
GetActiveMetricsAttributes() []attribute.KeyValue | ||
IsEndTimeSet() bool | ||
} | ||
|
||
type ActiveMetricsObjectWrapper struct { | ||
Obj ActiveMetricsObject | ||
} | ||
|
||
func NewActiveMetricsObjectWrapperFromClientObject(object client.Object) (*ActiveMetricsObjectWrapper, error) { | ||
amo, ok := object.(ActiveMetricsObject) | ||
if !ok { | ||
return nil, ErrCannotWrapToActiveMetricsObject | ||
} | ||
return &ActiveMetricsObjectWrapper{Obj: amo}, nil | ||
} | ||
|
||
func (amo ActiveMetricsObjectWrapper) GetActiveMetricsAttributes() []attribute.KeyValue { | ||
return amo.Obj.GetActiveMetricsAttributes() | ||
} | ||
|
||
func (amo ActiveMetricsObjectWrapper) IsEndTimeSet() bool { | ||
return amo.Obj.IsEndTimeSet() | ||
} |
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,44 @@ | ||
package common | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/keptn/lifecycle-toolkit/operator/api/v1alpha1" | ||
"github.com/keptn/lifecycle-toolkit/operator/api/v1alpha1/common" | ||
"github.com/keptn/lifecycle-toolkit/operator/controllers/common/fake" | ||
"github.com/stretchr/testify/require" | ||
"go.opentelemetry.io/otel/attribute" | ||
) | ||
|
||
func TestActiveMetricsObjectWrapper(t *testing.T) { | ||
appVersion := v1alpha1.KeptnAppVersion{ | ||
Status: v1alpha1.KeptnAppVersionStatus{ | ||
Status: common.StateFailed, | ||
CurrentPhase: "test", | ||
}, | ||
} | ||
|
||
object, err := NewActiveMetricsObjectWrapperFromClientObject(&appVersion) | ||
require.Nil(t, err) | ||
|
||
require.False(t, object.IsEndTimeSet()) | ||
} | ||
|
||
func TestActiveMetricsObject(t *testing.T) { | ||
activeMetricsObjectMock := fake.ActiveMetricsObjectMock{ | ||
GetActiveMetricsAttributesFunc: func() []attribute.KeyValue { | ||
return nil | ||
}, | ||
IsEndTimeSetFunc: func() bool { | ||
return true | ||
}, | ||
} | ||
|
||
wrapper := ActiveMetricsObjectWrapper{Obj: &activeMetricsObjectMock} | ||
|
||
_ = wrapper.GetActiveMetricsAttributes() | ||
require.Len(t, activeMetricsObjectMock.GetActiveMetricsAttributesCalls(), 1) | ||
|
||
_ = wrapper.IsEndTimeSet() | ||
require.Len(t, activeMetricsObjectMock.IsEndTimeSetCalls(), 1) | ||
} |
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
99 changes: 99 additions & 0 deletions
99
operator/controllers/common/fake/activemetricsobject_mock.go
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.