This repository has been archived by the owner on Dec 18, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Enda Phelan
committed
May 17, 2019
1 parent
bcdb879
commit 8f53140
Showing
4 changed files
with
200 additions
and
97 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,101 +1,188 @@ | ||
package mobilesecurityservice | ||
|
||
// func TestReconcileMobileSecurityService_updateStatus(t *testing.T) { | ||
// type fields struct { | ||
// client client.Client | ||
// scheme *runtime.Scheme | ||
// } | ||
// type args struct { | ||
// reqLogger logr.Logger | ||
// configMapStatus *corev1.ConfigMap | ||
// deploymentStatus *v1beta1.Deployment | ||
// serviceStatus *corev1.Service | ||
// routeStatus *routev1.Route | ||
// request reconcile.Request | ||
// } | ||
// tests := []struct { | ||
// name string | ||
// fields fields | ||
// args args | ||
// wantErr bool | ||
// }{ | ||
// // TODO: Add test cases. | ||
// } | ||
// for _, tt := range tests { | ||
// t.Run(tt.name, func(t *testing.T) { | ||
// r := &ReconcileMobileSecurityService{ | ||
// client: tt.fields.client, | ||
// scheme: tt.fields.scheme, | ||
// } | ||
// if err := r.updateStatus(tt.args.reqLogger, tt.args.configMapStatus, tt.args.deploymentStatus, tt.args.serviceStatus, tt.args.routeStatus, tt.args.request); (err != nil) != tt.wantErr { | ||
// t.Errorf("ReconcileMobileSecurityService.updateStatus() error = %v, wantErr %v", err, tt.wantErr) | ||
// } | ||
// }) | ||
// } | ||
// } | ||
import ( | ||
"reflect" | ||
"testing" | ||
|
||
// func TestReconcileMobileSecurityService_updateConfigMapStatus(t *testing.T) { | ||
// type fields struct { | ||
// instance *mobilesecurityservicev1alpha1.MobileSecurityService | ||
// scheme *runtime.Scheme | ||
// } | ||
// tests := []struct { | ||
// name string | ||
// fields fields | ||
// want *corev1.ConfigMap | ||
// wantErr bool | ||
// }{ | ||
// { | ||
// name: "should update the ConfigMap status", | ||
// fields: fields{ | ||
// instance: &instance, | ||
// scheme: scheme.Scheme, | ||
// }, | ||
// want: &corev1.ConfigMap{ | ||
// TypeMeta: metav1.TypeMeta{ | ||
// APIVersion: "v1", | ||
// Kind: "ConfigMap", | ||
// }, | ||
// ObjectMeta: metav1.ObjectMeta{ | ||
// Name: utils.GetConfigMapName(&instance), | ||
// Namespace: instance.Namespace, | ||
// Labels: getAppLabels(instance.Name), | ||
// }, | ||
// Data: getAppEnvVarsMap(&instance), | ||
// }, | ||
// wantErr: false, | ||
// }, | ||
// } | ||
// for _, tt := range tests { | ||
// t.Run(tt.name, func(t *testing.T) { | ||
// objs := []runtime.Object{tt.fields.instance} | ||
mobilesecurityservicev1alpha1 "github.com/aerogear/mobile-security-service-operator/pkg/apis/mobilesecurityservice/v1alpha1" | ||
"github.com/aerogear/mobile-security-service-operator/pkg/utils" | ||
routev1 "github.com/openshift/api/route/v1" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/api/extensions/v1beta1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apimachinery/pkg/types" | ||
"k8s.io/client-go/kubernetes/scheme" | ||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
) | ||
|
||
// r, _ := getReconciler(objs) | ||
func TestReconcileMobileSecurityService_updateStatus(t *testing.T) { | ||
type fields struct { | ||
instance *mobilesecurityservicev1alpha1.MobileSecurityService | ||
objs []runtime.Object | ||
scheme *runtime.Scheme | ||
} | ||
type args struct { | ||
request reconcile.Request | ||
configMap *corev1.ConfigMap | ||
deployment *v1beta1.Deployment | ||
service *corev1.Service | ||
route *routev1.Route | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "Should return error as the resources have not been created", | ||
fields: fields{ | ||
instance: &instanceOne, | ||
objs: []runtime.Object{&instanceOne}, | ||
scheme: scheme.Scheme, | ||
}, | ||
args: args{ | ||
request: reconcile.Request{ | ||
NamespacedName: types.NamespacedName{ | ||
Name: instanceOne.Name, | ||
Namespace: instanceOne.Namespace, | ||
}, | ||
}, | ||
configMap: &corev1.ConfigMap{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: "v1", | ||
Kind: "ConfigMap", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: utils.GetConfigMapName(&instanceOne), | ||
Namespace: instanceOne.Namespace, | ||
Labels: getAppLabels(instanceOne.Name), | ||
}, | ||
Data: getAppEnvVarsMap(&instanceOne), | ||
}, | ||
deployment: &v1beta1.Deployment{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: "extensions/v1beta1", | ||
Kind: "Deployment", | ||
}, | ||
}, | ||
service: &corev1.Service{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: "v1", | ||
Kind: "Service", | ||
}, | ||
}, | ||
route: &routev1.Route{ | ||
TypeMeta: v1.TypeMeta{ | ||
APIVersion: "v1", | ||
Kind: "Route", | ||
}, | ||
}, | ||
}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
objs := []runtime.Object{tt.fields.instance} | ||
|
||
// req := reconcile.Request{ | ||
// NamespacedName: types.NamespacedName{ | ||
// Name: tt.fields.instance.Name, | ||
// Namespace: tt.fields.instance.Namespace, | ||
// }, | ||
// } | ||
r := getReconciler(objs) | ||
|
||
// reqLogger := log.WithValues("Request.Namespace", req.Namespace, "Request.Name", req.Name) | ||
reqLogger := log.WithValues("Request.Namespace", tt.args.request.Namespace, "Request.Name", tt.args.request.Name) | ||
|
||
// // call reconcile to create the MobileSecurityService instance | ||
// _, err := r.Reconcile(req) | ||
// if err != nil { | ||
// t.Fatalf("reconcile: (%v)", err) | ||
// } | ||
if err := r.updateStatus(reqLogger, tt.args.configMap, tt.args.deployment, tt.args.service, tt.args.route, tt.args.request); (err != nil) != tt.wantErr { | ||
t.Errorf("ReconcileMobileSecurityService.updateStatus() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
// got, err := r.updateConfigMapStatus(reqLogger, req) | ||
func TestReconcileMobileSecurityService_updateConfigMapStatus(t *testing.T) { | ||
type fields struct { | ||
instance *mobilesecurityservicev1alpha1.MobileSecurityService | ||
scheme *runtime.Scheme | ||
} | ||
type args struct { | ||
request reconcile.Request | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
args args | ||
want *corev1.ConfigMap | ||
wantErr bool | ||
shouldCreate bool | ||
}{ | ||
{ | ||
name: "should fail to find the ConfigMap", | ||
fields: fields{ | ||
instance: &instanceOne, | ||
scheme: scheme.Scheme, | ||
}, | ||
args: args{ | ||
request: reconcile.Request{ | ||
NamespacedName: types.NamespacedName{ | ||
Name: instanceOne.Name, | ||
Namespace: instanceOne.Namespace, | ||
}, | ||
}, | ||
}, | ||
want: nil, | ||
wantErr: true, | ||
}, | ||
{ | ||
name: "should update the ConfigMap status", | ||
fields: fields{ | ||
instance: &instanceOne, | ||
scheme: scheme.Scheme, | ||
}, | ||
args: args{ | ||
request: reconcile.Request{ | ||
NamespacedName: types.NamespacedName{ | ||
Name: instanceOne.Name, | ||
Namespace: instanceOne.Namespace, | ||
}, | ||
}, | ||
}, | ||
want: &corev1.ConfigMap{ | ||
TypeMeta: metav1.TypeMeta{ | ||
APIVersion: "v1", | ||
Kind: "ConfigMap", | ||
}, | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: utils.GetConfigMapName(&instanceOne), | ||
Namespace: instanceOne.Namespace, | ||
Labels: getAppLabels(instanceOne.Name), | ||
}, | ||
Data: getAppEnvVarsMap(&instanceOne), | ||
}, | ||
shouldCreate: true, | ||
wantErr: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
objs := []runtime.Object{tt.fields.instance} | ||
|
||
// // if (err != nil) != tt.wantErr { | ||
// // t.Errorf("ReconcileMobileSecurityService.updateConfigMapStatus() error = %v, wantErr %v", err, tt.wantErr) | ||
// // return | ||
// // } | ||
// // if !reflect.DeepEqual(got, tt.want) { | ||
// // t.Errorf("ReconcileMobileSecurityService.updateConfigMapStatus() = %v, want %v", got, tt.want) | ||
// // } | ||
// }) | ||
// } | ||
// } | ||
r := getReconciler(objs) | ||
|
||
reqLogger := log.WithValues("Request.Namespace", tt.args.request.Namespace, "Request.Name", tt.args.request.Name) | ||
|
||
if tt.shouldCreate { | ||
r.create(&instanceOne, reqLogger, CONFIGMAP) | ||
} | ||
|
||
got, err := r.updateConfigMapStatus(reqLogger, tt.args.request) | ||
|
||
if (err != nil) != tt.wantErr { | ||
t.Errorf("ReconcileMobileSecurityService.updateConfigMapStatus() error = %v, wantErr %v", err, tt.wantErr) | ||
return | ||
} | ||
if (got != nil && tt.want != nil) && !reflect.DeepEqual(got.Name, tt.want.Name) { | ||
t.Errorf("ReconcileMobileSecurityService.updateConfigMapStatus() = %v, want %v", got.Name, tt.want.Name) | ||
} | ||
}) | ||
} | ||
} |