Skip to content

Commit

Permalink
Fix apimanager_controller_test upgrade to take into account smtp migr…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
miguelsorianod committed Dec 18, 2019
1 parent 5c2c3ff commit 3992aca
Showing 1 changed file with 88 additions and 2 deletions.
90 changes: 88 additions & 2 deletions pkg/controller/apimanager/apimanager_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"fmt"
"testing"

"github.com/3scale/3scale-operator/pkg/3scale/amp/component"

"github.com/3scale/3scale-operator/pkg/3scale/amp/operator"
"github.com/3scale/3scale-operator/pkg/3scale/amp/product"
appsv1alpha1 "github.com/3scale/3scale-operator/pkg/apis/apps/v1alpha1"
Expand Down Expand Up @@ -151,11 +153,64 @@ func TestAPIManagerControllerUpgrade(t *testing.T) {
},
},
},
Template: &corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
corev1.Container{
Name: "system-master",
},
corev1.Container{
Name: "system-developer",
},
corev1.Container{
Name: "system-provider",
},
},
},
},
},
}

systemSidekiq := &appsv1.DeploymentConfig{
ObjectMeta: metav1.ObjectMeta{
Name: "system-sidekiq",
Namespace: namespace,
},
Spec: appsv1.DeploymentConfigSpec{
Template: &corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
corev1.Container{
Name: "system-sidekiq",
},
},
},
},
},
}

smtpConfigMapToReplace := corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "ConfigMap",
},
ObjectMeta: metav1.ObjectMeta{
Name: "smtp",
Namespace: namespace,
},
Data: map[string]string{
component.SystemSecretSystemSMTPAddressFieldName: "myaddress@domain.com",
component.SystemSecretSystemSMTPUserNameFieldName: "myusername",
component.SystemSecretSystemSMTPPasswordFieldName: "mypassword",
component.SystemSecretSystemSMTPDomainFieldName: "mydomain",
component.SystemSecretSystemSMTPPortFieldName: "25",
component.SystemSecretSystemSMTPAuthenticationFieldName: "login",
component.SystemSecretSystemSMTPOpenSSLVerifyModeFieldName: "none",
},
}

// Objects to track in the fake client.
objs := []runtime.Object{apimanager, systemApp}
objs := []runtime.Object{apimanager, systemApp, systemSidekiq, &smtpConfigMapToReplace}

// Register operator types with the runtime scheme.
s := scheme.Scheme
Expand Down Expand Up @@ -207,14 +262,45 @@ func TestAPIManagerControllerUpgrade(t *testing.T) {
}

if !res.Requeue {
t.Error("upgrade not expected to finish. Should requeue before update annotations")
t.Error("upgrade not expected to finish. Should requeue before update system-app pre-hook pod")
}

res, err = r.Reconcile(req)
if err != nil {
t.Fatalf("reconcile: (%v)", err)
}

if !res.Requeue {
t.Error("upgrade not expected to finish. Should requeue after migrating smtp ConfigMap to system-smtp Secret")
}

res, err = r.Reconcile(req)
if err != nil {
t.Fatalf("reconcile: (%v)", err)
}

if !res.Requeue {
t.Error("upgrade not expected to finish. Should requeue after updating smtp envvars in system-sidekiq")
}

res, err = r.Reconcile(req)
if err != nil {
t.Fatalf("reconcile: (%v)", err)
}

if !res.Requeue {
t.Error("upgrade not expected to finish. Should requeue after updating smtp envvars in system-app")
}

res, err = r.Reconcile(req)
if err != nil {
t.Fatalf("reconcile: (%v)", err)
}

if !res.Requeue {
t.Error("upgrade not expected to finish. Should requeue before update annotations")
}

finalAPIManager := &appsv1alpha1.APIManager{}
err = r.Client().Get(context.TODO(), req.NamespacedName, finalAPIManager)
if err != nil {
Expand Down

0 comments on commit 3992aca

Please sign in to comment.