Skip to content

Commit

Permalink
#221 fix some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jelemux committed Dec 20, 2024
1 parent 4bfac30 commit 0d6ab29
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 22 deletions.
11 changes: 6 additions & 5 deletions controllers/doguSupportManager_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package controllers

import (
cescommons "github.com/cloudogu/ces-commons-lib/dogu"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -130,7 +131,7 @@ func Test_doguSupportManager_updateDeployment(t *testing.T) {
ldapCr := readDoguCr(t, ldapCrBytes)
ldapCr.Namespace = namespace
ldapCr.Spec.SupportMode = true
sut.localDoguFetcherMock.EXPECT().FetchInstalled(testCtx, "ldap").Return(ldap, nil)
sut.localDoguFetcherMock.EXPECT().FetchInstalled(testCtx, cescommons.SimpleName("ldap")).Return(ldap, nil)

deployment := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "ldap", Namespace: namespace}}
err := sut.supportManager.client.Create(testCtx, deployment)
Expand Down Expand Up @@ -183,7 +184,7 @@ func Test_doguSupportManager_updateDeployment(t *testing.T) {
// given
sut := getDoguSupportManagerWithMocks(t, getTestScheme())
ldapCr := readDoguCr(t, ldapCrBytes)
sut.localDoguFetcherMock.EXPECT().FetchInstalled(testCtx, "ldap").Return(nil, assert.AnError)
sut.localDoguFetcherMock.EXPECT().FetchInstalled(testCtx, cescommons.SimpleName("ldap")).Return(nil, assert.AnError)

deployment := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "ldap", Namespace: namespace}}
err := sut.supportManager.client.Create(testCtx, deployment)
Expand All @@ -202,7 +203,7 @@ func Test_doguSupportManager_updateDeployment(t *testing.T) {
sut := getDoguSupportManagerWithMocks(t, getTestScheme())
ldap := readDoguDescriptor(t, ldapDoguDescriptorBytes)
ldapCr := readDoguCr(t, ldapCrBytes)
sut.localDoguFetcherMock.EXPECT().FetchInstalled(testCtx, "ldap").Return(ldap, nil)
sut.localDoguFetcherMock.EXPECT().FetchInstalled(testCtx, cescommons.SimpleName("ldap")).Return(ldap, nil)
podSpec := corev1.PodTemplateSpec{Spec: corev1.PodSpec{}}
sut.podTemplateGenerator.EXPECT().GetPodTemplate(testCtx, ldapCr, ldap).Return(&podSpec, nil)

Expand All @@ -223,7 +224,7 @@ func Test_doguSupportManager_HandleSupportMode(t *testing.T) {
ldapCr := readDoguCr(t, ldapCrBytes)
ldapCr.Namespace = namespace
ldapCr.Spec.SupportMode = true
sut.localDoguFetcherMock.EXPECT().FetchInstalled(testCtx, "ldap").Return(ldap, nil)
sut.localDoguFetcherMock.EXPECT().FetchInstalled(testCtx, cescommons.SimpleName("ldap")).Return(ldap, nil)
sut.recorderMock.On("Eventf", ldapCr, "Normal", "Support", "Support flag changed to %t. Deployment updated.", true)

podTemplateSpec := corev1.PodTemplateSpec{
Expand Down Expand Up @@ -302,7 +303,7 @@ func Test_doguSupportManager_HandleSupportMode(t *testing.T) {
ldapCr := readDoguCr(t, ldapCrBytes)
ldapCr.Namespace = namespace
ldapCr.Spec.SupportMode = true
sut.localDoguFetcherMock.EXPECT().FetchInstalled(testCtx, "ldap").Return(nil, assert.AnError)
sut.localDoguFetcherMock.EXPECT().FetchInstalled(testCtx, cescommons.SimpleName("ldap")).Return(nil, assert.AnError)

deployment := &appsv1.Deployment{ObjectMeta: metav1.ObjectMeta{Name: "ldap", Namespace: namespace},
Spec: appsv1.DeploymentSpec{
Expand Down
17 changes: 9 additions & 8 deletions controllers/doguUpgradeManager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controllers

import (
"context"
cescommons "github.com/cloudogu/ces-commons-lib/dogu"
"github.com/cloudogu/k8s-dogu-operator/v3/api/ecoSystem"
"github.com/cloudogu/k8s-dogu-operator/v3/controllers/util"
"github.com/stretchr/testify/mock"
Expand Down Expand Up @@ -124,7 +125,7 @@ func Test_doguUpgradeManager_Upgrade(t *testing.T) {
recorderMock.On("Eventf", redmineCr, corev1.EventTypeNormal, upgrade.EventReason, "Executing upgrade from %s to %s...", "4.2.3-10", upgradeVersion)

localFetcher := newMockLocalDoguFetcher(t)
localFetcher.EXPECT().FetchInstalled(testCtx, "redmine").Return(redmineDoguInstalled, nil)
localFetcher.EXPECT().FetchInstalled(testCtx, cescommons.SimpleName("redmine")).Return(redmineDoguInstalled, nil)

resourceFetcher := newMockResourceDoguFetcher(t)
resourceFetcher.On("FetchWithResource", testCtx, redmineCr).Return(redmineDoguUpgrade, nil, nil)
Expand Down Expand Up @@ -182,7 +183,7 @@ func Test_doguUpgradeManager_Upgrade(t *testing.T) {
recorderMock.On("Eventf", redmineCr, corev1.EventTypeNormal, upgrade.EventReason, "Executing upgrade from %s to %s...", "4.2.3-10", upgradeVersion)

localFetcher := newMockLocalDoguFetcher(t)
localFetcher.EXPECT().FetchInstalled(testCtx, "redmine").Return(redmineDoguInstalled, nil)
localFetcher.EXPECT().FetchInstalled(testCtx, cescommons.SimpleName("redmine")).Return(redmineDoguInstalled, nil)

devDoguMap := &v2.DevelopmentDoguMap{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -251,7 +252,7 @@ func Test_doguUpgradeManager_Upgrade(t *testing.T) {
recorderMock.On("Eventf", redmineCr, corev1.EventTypeNormal, upgrade.EventReason, "Executing upgrade from %s to %s...", "4.2.3-10", "4.2.3-11")

localFetcher := newMockLocalDoguFetcher(t)
localFetcher.EXPECT().FetchInstalled(testCtx, "redmine").Return(redmineDoguInstalled, nil)
localFetcher.EXPECT().FetchInstalled(testCtx, cescommons.SimpleName("redmine")).Return(redmineDoguInstalled, nil)

resourceFetcher := newMockResourceDoguFetcher(t)
resourceFetcher.On("FetchWithResource", testCtx, redmineCr).Return(redmineDoguUpgrade, nil, nil)
Expand Down Expand Up @@ -301,7 +302,7 @@ func Test_doguUpgradeManager_Upgrade(t *testing.T) {
recorderMock.On("Event", redmineCr, corev1.EventTypeNormal, upgrade.EventReason, "Checking premises...")

localFetcher := newMockLocalDoguFetcher(t)
localFetcher.EXPECT().FetchInstalled(testCtx, "redmine").Return(redmineDoguInstalled, nil)
localFetcher.EXPECT().FetchInstalled(testCtx, cescommons.SimpleName("redmine")).Return(redmineDoguInstalled, nil)

resourceFetcher := newMockResourceDoguFetcher(t)
resourceFetcher.On("FetchWithResource", testCtx, redmineCr).Return(redmineDoguUpgrade, nil, nil)
Expand Down Expand Up @@ -349,7 +350,7 @@ func Test_doguUpgradeManager_Upgrade(t *testing.T) {
recorderMock := newMockEventRecorder(t)

localFetcher := newMockLocalDoguFetcher(t)
localFetcher.EXPECT().FetchInstalled(testCtx, "redmine").Return(redmineDoguInstalled, nil)
localFetcher.EXPECT().FetchInstalled(testCtx, cescommons.SimpleName("redmine")).Return(redmineDoguInstalled, nil)

resourceFetcher := newMockResourceDoguFetcher(t)
resourceFetcher.On("FetchWithResource", testCtx, redmineCr).Return(nil, nil, assert.AnError)
Expand Down Expand Up @@ -391,7 +392,7 @@ func Test_doguUpgradeManager_Upgrade(t *testing.T) {
recorderMock := newMockEventRecorder(t)

localFetcher := newMockLocalDoguFetcher(t)
localFetcher.EXPECT().FetchInstalled(testCtx, "redmine").Return(nil, assert.AnError)
localFetcher.EXPECT().FetchInstalled(testCtx, cescommons.SimpleName("redmine")).Return(nil, assert.AnError)

resourceFetcher := newMockResourceDoguFetcher(t)

Expand Down Expand Up @@ -458,7 +459,7 @@ func Test_doguUpgradeManager_Upgrade(t *testing.T) {
recorderMock.On("Eventf", redmineCr, corev1.EventTypeNormal, upgrade.EventReason, "Executing upgrade from %s to %s...", "4.2.3-10", upgradeVersion)

localFetcher := newMockLocalDoguFetcher(t)
localFetcher.EXPECT().FetchInstalled(testCtx, "").Return(redmineDoguInstalled, nil)
localFetcher.EXPECT().FetchInstalled(testCtx, cescommons.SimpleName("")).Return(redmineDoguInstalled, nil)

resourceFetcher := newMockResourceDoguFetcher(t)
resourceFetcher.On("FetchWithResource", testCtx, redmineCr).Return(redmineDoguUpgrade, nil, nil)
Expand Down Expand Up @@ -500,7 +501,7 @@ func Test_doguUpgradeManager_Upgrade(t *testing.T) {
recorderMock.On("Eventf", redmineCr, corev1.EventTypeNormal, upgrade.EventReason, "Executing upgrade from %s to %s...", "4.2.3-10", upgradeVersion)

localFetcher := newMockLocalDoguFetcher(t)
localFetcher.EXPECT().FetchInstalled(testCtx, "").Return(redmineDoguInstalled, nil)
localFetcher.EXPECT().FetchInstalled(testCtx, cescommons.SimpleName("")).Return(redmineDoguInstalled, nil)

resourceFetcher := newMockResourceDoguFetcher(t)
resourceFetcher.On("FetchWithResource", testCtx, redmineCr).Return(redmineDoguUpgrade, nil, nil)
Expand Down
19 changes: 10 additions & 9 deletions controllers/dogu_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"encoding/json"
"fmt"
cescommons "github.com/cloudogu/ces-commons-lib/dogu"
appsv1 "k8s.io/api/apps/v1"
"testing"
"time"
Expand Down Expand Up @@ -42,7 +43,7 @@ func Test_evaluateRequiredOperation(t *testing.T) {
recorder := newMockEventRecorder(t)
localDogu := &core.Dogu{Name: "official/ledogu", Version: "42.0.0-1"}
localDoguFetcher := newMockLocalDoguFetcher(t)
localDoguFetcher.EXPECT().FetchInstalled(testCtx, "ledogu").Return(localDogu, nil)
localDoguFetcher.EXPECT().FetchInstalled(testCtx, cescommons.SimpleName("ledogu")).Return(localDogu, nil)

doguService := &v1.Service{ObjectMeta: metav1.ObjectMeta{Name: "ledogu"}}
fakeClient := fake.NewClientBuilder().WithObjects(doguService).Build()
Expand Down Expand Up @@ -73,7 +74,7 @@ func Test_evaluateRequiredOperation(t *testing.T) {
recorder := newMockEventRecorder(t)
localDogu := &core.Dogu{Name: "official/ledogu", Version: "42.0.0-1"}
localDoguFetcher := newMockLocalDoguFetcher(t)
localDoguFetcher.EXPECT().FetchInstalled(testCtx, "ledogu").Return(localDogu, nil)
localDoguFetcher.EXPECT().FetchInstalled(testCtx, cescommons.SimpleName("ledogu")).Return(localDogu, nil)

doguService := &v1.Service{ObjectMeta: metav1.ObjectMeta{Name: "ledogu"}}
fakeClient := fake.NewClientBuilder().WithObjects(doguService).Build()
Expand Down Expand Up @@ -105,7 +106,7 @@ func Test_evaluateRequiredOperation(t *testing.T) {
recorder.On("Eventf", testDoguCr, v1.EventTypeWarning, operatorEventReason, mock.Anything, mock.Anything)
localDogu := &core.Dogu{Name: "official/ledogu", Version: "42.0.0-1"}
localDoguFetcher := newMockLocalDoguFetcher(t)
localDoguFetcher.EXPECT().FetchInstalled(testCtx, "ledogu").Return(localDogu, nil)
localDoguFetcher.EXPECT().FetchInstalled(testCtx, cescommons.SimpleName("ledogu")).Return(localDogu, nil)

doguService := &v1.Service{ObjectMeta: metav1.ObjectMeta{Name: "ledogu"}}
fakeClient := fake.NewClientBuilder().WithObjects(doguService).Build()
Expand Down Expand Up @@ -165,7 +166,7 @@ func Test_evaluateRequiredOperation(t *testing.T) {

localDogu := &core.Dogu{Name: "official/ledogu", Version: "42.0.0-1"}
localDoguFetcher := newMockLocalDoguFetcher(t)
localDoguFetcher.EXPECT().FetchInstalled(testCtx, "ledogu").Return(localDogu, nil)
localDoguFetcher.EXPECT().FetchInstalled(testCtx, cescommons.SimpleName("ledogu")).Return(localDogu, nil)

doguService := &v1.Service{ObjectMeta: metav1.ObjectMeta{Name: "ledogu"}}
fakeClient := fake.NewClientBuilder().WithObjects(doguService).Build()
Expand Down Expand Up @@ -200,7 +201,7 @@ func Test_evaluateRequiredOperation(t *testing.T) {

localDogu := &core.Dogu{Name: "official/ledogu", Version: "42.0.0-1"}
localDoguFetcher := newMockLocalDoguFetcher(t)
localDoguFetcher.EXPECT().FetchInstalled(testCtx, "ledogu").Return(localDogu, nil)
localDoguFetcher.EXPECT().FetchInstalled(testCtx, cescommons.SimpleName("ledogu")).Return(localDogu, nil)

doguService := &v1.Service{ObjectMeta: metav1.ObjectMeta{Name: "ledogu"}}
fakeClient := fake.NewClientBuilder().WithObjects(doguService).Build()
Expand Down Expand Up @@ -239,7 +240,7 @@ func Test_evaluateRequiredOperation(t *testing.T) {

localDogu := &core.Dogu{Name: "official/ledogu", Version: "42.0.0-1"}
localDoguFetcher := newMockLocalDoguFetcher(t)
localDoguFetcher.EXPECT().FetchInstalled(testCtx, "ledogu").Return(localDogu, nil)
localDoguFetcher.EXPECT().FetchInstalled(testCtx, cescommons.SimpleName("ledogu")).Return(localDogu, nil)

doguService := &v1.Service{ObjectMeta: metav1.ObjectMeta{Name: "ledogu"}}
fakeClient := fake.NewClientBuilder().WithObjects(doguService).Build()
Expand Down Expand Up @@ -315,7 +316,7 @@ func Test_evaluateRequiredOperation(t *testing.T) {

localDogu := &core.Dogu{Name: "official/ledogu", Version: "42.0.0-1"}
localDoguFetcher := newMockLocalDoguFetcher(t)
localDoguFetcher.EXPECT().FetchInstalled(testCtx, "ledogu").Return(localDogu, nil)
localDoguFetcher.EXPECT().FetchInstalled(testCtx, cescommons.SimpleName("ledogu")).Return(localDogu, nil)

doguService := &v1.Service{ObjectMeta: metav1.ObjectMeta{Name: "ledogu"}}
fakeClient := fake.NewClientBuilder().WithObjects(doguService).Build()
Expand Down Expand Up @@ -354,7 +355,7 @@ func Test_evaluateRequiredOperation(t *testing.T) {

localDogu := &core.Dogu{Name: "official/ledogu", Version: "42.0.0-1"}
localDoguFetcher := newMockLocalDoguFetcher(t)
localDoguFetcher.EXPECT().FetchInstalled(testCtx, "ledogu").Return(localDogu, nil)
localDoguFetcher.EXPECT().FetchInstalled(testCtx, cescommons.SimpleName("ledogu")).Return(localDogu, nil)

doguService := &v1.Service{ObjectMeta: metav1.ObjectMeta{Name: "ledogu"}}
fakeClient := fake.NewClientBuilder().WithObjects(doguService).Build()
Expand Down Expand Up @@ -431,7 +432,7 @@ func Test_evaluateRequiredOperation(t *testing.T) {

localDogu := &core.Dogu{Name: "official/ledogu", Version: "42.0.0-1"}
localDoguFetcher := newMockLocalDoguFetcher(t)
localDoguFetcher.EXPECT().FetchInstalled(testCtx, "ledogu").Return(localDogu, nil)
localDoguFetcher.EXPECT().FetchInstalled(testCtx, cescommons.SimpleName("ledogu")).Return(localDogu, nil)

doguService := &v1.Service{ObjectMeta: metav1.ObjectMeta{Name: "ledogu"}}
fakeClient := fake.NewClientBuilder().WithObjects(doguService).Build()
Expand Down

0 comments on commit 0d6ab29

Please sign in to comment.