Skip to content

Commit

Permalink
fix unit test
Browse files Browse the repository at this point in the history
Signed-off-by: odubajDT <ondrej.dubaj@dynatrace.com>
  • Loading branch information
odubajDT committed Sep 19, 2023
1 parent 87e161d commit eec8d45
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 30 deletions.
14 changes: 0 additions & 14 deletions lifecycle-operator/controllers/common/test_utils.go
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package common

import (
"context"
"fmt"

lfcv1alpha3 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3"
apicommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3/common"
"go.opentelemetry.io/otel/metric"
sdkmetric "go.opentelemetry.io/otel/sdk/metric"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func GetApp(name string) *lfcv1alpha3.KeptnApp {
Expand All @@ -29,17 +26,6 @@ func GetApp(name string) *lfcv1alpha3.KeptnApp {
return app
}

func UpdateAppRevision(c client.Client, name string, revision uint) error {
app := &lfcv1alpha3.KeptnApp{}
err := c.Get(context.TODO(), types.NamespacedName{Namespace: "default", Name: name}, app)
if err != nil {
return err
}
app.Spec.Revision = revision
app.Generation = int64(revision)
return c.Update(context.TODO(), app)
}

func ReturnAppVersion(namespace string, appName string, version string, workloads []lfcv1alpha3.KeptnWorkloadRef, status lfcv1alpha3.KeptnAppVersionStatus) *lfcv1alpha3.KeptnAppVersion {
appVersionName := fmt.Sprintf("%s-%s", appName, version)
app := &lfcv1alpha3.KeptnAppVersion{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"reflect"
"sigs.k8s.io/controller-runtime/pkg/client"
"testing"

lfcv1alpha3 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1alpha3"
Expand All @@ -19,6 +18,7 @@ import (
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/record"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
)

Expand Down Expand Up @@ -150,24 +150,17 @@ func TestKeptnAppReconciler_reconcile(t *testing.T) {
func TestKeptnAppReconciler_deprecateAppVersions(t *testing.T) {

app := controllercommon.GetApp("myapp")
r, _, _ := setupReconciler(app)
_, err := r.Reconcile(context.TODO(), ctrl.Request{
NamespacedName: types.NamespacedName{
app.Spec.Revision = uint(2)
app.Generation = int64(2)
appVersion := &lfcv1alpha3.KeptnAppVersion{
ObjectMeta: metav1.ObjectMeta{
Name: "myapp-1.0.0-6b86b273",
Namespace: "default",
Name: "myapp",
},
})

require.Nil(t, err)

keptnappversion := &lfcv1alpha3.KeptnAppVersion{}
err = r.Client.Get(context.TODO(), types.NamespacedName{Namespace: "default", Name: "myapp-1.0.0-6b86b273"}, keptnappversion)
require.Nil(t, err)

err = controllercommon.UpdateAppRevision(r.Client, "myapp", 2)
require.Nil(t, err)
}
r, _, _ := setupReconciler(app, appVersion)

_, err = r.Reconcile(context.TODO(), ctrl.Request{
_, err := r.Reconcile(context.TODO(), ctrl.Request{
NamespacedName: types.NamespacedName{
Namespace: "default",
Name: "myapp",
Expand All @@ -176,6 +169,7 @@ func TestKeptnAppReconciler_deprecateAppVersions(t *testing.T) {

require.Nil(t, err)

keptnappversion := &lfcv1alpha3.KeptnAppVersion{}
err = r.Client.Get(context.TODO(), types.NamespacedName{Namespace: "default", Name: "myapp-1.0.0-d4735e3a"}, keptnappversion)
require.Nil(t, err)

Expand Down

0 comments on commit eec8d45

Please sign in to comment.