Skip to content

Commit

Permalink
touch up unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverMKing committed Jan 11, 2024
1 parent e79ad1c commit 7a758be
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 1 deletion.
8 changes: 8 additions & 0 deletions testing/e2e/manifests/clientServer.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ func ClientAndServer(namespace, name, zoneName, nameserver, keyvaultURI string,

service :=
&corev1.Service{
TypeMeta: metav1.TypeMeta{
Kind: "Service",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: serviceName,
Namespace: namespace,
Expand All @@ -107,6 +111,10 @@ func ClientAndServer(namespace, name, zoneName, nameserver, keyvaultURI string,
},
}
ingress := &netv1.Ingress{
TypeMeta: metav1.TypeMeta{
Kind: "Ingress",
APIVersion: "networking.k8s.io/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: ingressName,
Namespace: namespace,
Expand Down
8 changes: 8 additions & 0 deletions testing/e2e/manifests/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,10 @@ func newGoDeployment(contents, namespace, name string) *appsv1.Deployment {
}

return &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
Kind: "Deployment",
APIVersion: "apps/v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
Namespace: namespace,
Expand Down Expand Up @@ -102,6 +106,10 @@ func newGoDeployment(contents, namespace, name string) *appsv1.Deployment {
// UncollisionedNs returns a namespace with a guaranteed unique name after creating the namespace
func UncollisionedNs() *corev1.Namespace {
return &corev1.Namespace{
TypeMeta: metav1.TypeMeta{
Kind: "Namespace",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
GenerateName: "app-routing-e2e-",
Labels: map[string]string{
Expand Down
16 changes: 16 additions & 0 deletions testing/e2e/manifests/e2e.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@ const (
func E2e(image, loadableProvisionedJson string) []client.Object {
ret := []client.Object{
&corev1.ServiceAccount{
TypeMeta: metav1.TypeMeta{
Kind: "ServiceAccount",
APIVersion: corev1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "app-routing-e2e",
Namespace: e2eNamespace,
},
},
&rbacv1.ClusterRoleBinding{
TypeMeta: metav1.TypeMeta{
Kind: "ClusterRoleBinding",
APIVersion: rbacv1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "app-routing-e2e",
},
Expand All @@ -39,6 +47,10 @@ func E2e(image, loadableProvisionedJson string) []client.Object {
},
},
&corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: corev1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "infrastructure",
Namespace: e2eNamespace,
Expand All @@ -48,6 +60,10 @@ func E2e(image, loadableProvisionedJson string) []client.Object {
},
},
&batchv1.Job{
TypeMeta: metav1.TypeMeta{
Kind: "Job",
APIVersion: batchv1.SchemeGroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: "app-routing-operator-e2e",
Namespace: e2eNamespace,
Expand Down
4 changes: 4 additions & 0 deletions testing/e2e/manifests/nginxIngressController.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (

func NewNginxIngressController(name, ingressClassName string) *v1alpha1.NginxIngressController {
return &v1alpha1.NginxIngressController{
TypeMeta: metav1.TypeMeta{
Kind: "NginxIngressController",
APIVersion: v1alpha1.GroupVersion.String(),
},
ObjectMeta: metav1.ObjectMeta{
Name: name,
},
Expand Down
20 changes: 20 additions & 0 deletions testing/e2e/manifests/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,19 +152,31 @@ func Operator(latestImage string, publicZones, privateZones []string, cfg *Opera
var ret []client.Object

namespace := &corev1.Namespace{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "Namespace",
},
ObjectMeta: metav1.ObjectMeta{
Name: managedResourceNs,
},
}

serviceAccount := &corev1.ServiceAccount{
TypeMeta: metav1.TypeMeta{
APIVersion: "v1",
Kind: "ServiceAccount",
},
ObjectMeta: metav1.ObjectMeta{
Name: "app-routing-operator",
Namespace: operatorNs,
},
}

clusterRoleBinding := &rbacv1.ClusterRoleBinding{
TypeMeta: metav1.TypeMeta{
APIVersion: "rbac.authorization.k8s.io/v1",
Kind: "ClusterRoleBinding",
},
ObjectMeta: metav1.ObjectMeta{
Name: "app-routing-operator",
Namespace: operatorNs,
Expand All @@ -184,6 +196,10 @@ func Operator(latestImage string, publicZones, privateZones []string, cfg *Opera
}

baseDeployment := &appsv1.Deployment{
TypeMeta: metav1.TypeMeta{
APIVersion: "apps/v1",
Kind: "Deployment",
},
ObjectMeta: metav1.ObjectMeta{
Name: "app-routing-operator",
Namespace: operatorNs,
Expand Down Expand Up @@ -241,6 +257,10 @@ func Operator(latestImage string, publicZones, privateZones []string, cfg *Opera
}

podDisrutptionBudget := &policyv1.PodDisruptionBudget{
TypeMeta: metav1.TypeMeta{
APIVersion: "policy/v1",
Kind: "PodDisruptionBudget",
},
ObjectMeta: metav1.ObjectMeta{
Name: "app-routing-operator",
Namespace: "app-routing-system",
Expand Down
12 changes: 12 additions & 0 deletions testing/e2e/manifests/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ scrape_configs:

server := []client.Object{
&corev1.ConfigMap{
TypeMeta: metav1.TypeMeta{
Kind: "ConfigMap",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: name + "-server",
Namespace: namespace,
Expand All @@ -110,6 +114,10 @@ scrape_configs:
},
},
&corev1.ServiceAccount{
TypeMeta: metav1.TypeMeta{
Kind: "ServiceAccount",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: name + "-server",
Namespace: namespace,
Expand Down Expand Up @@ -213,6 +221,10 @@ scrape_configs:
},
},
&corev1.Service{
TypeMeta: metav1.TypeMeta{
Kind: "Service",
APIVersion: "v1",
},
ObjectMeta: metav1.ObjectMeta{
Name: name + "-server",
Namespace: namespace,
Expand Down
2 changes: 1 addition & 1 deletion testing/e2e/suites/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func upsert(ctx context.Context, c client.Client, obj client.Object) error {
}

lgr.Info("object already exists, attempting to update")
if err := c.Update(ctx, copy); err != nil {
if err := c.Patch(ctx, copy, client.Apply, client.ForceOwnership, client.FieldOwner("e2e-test")); err != nil {
return fmt.Errorf("updating object: %w", err)
}

Expand Down

0 comments on commit 7a758be

Please sign in to comment.