Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
test(jupyterlab): add test table to deployment function
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonBirchall committed May 4, 2022
1 parent 8fcb280 commit f2162b3
Showing 1 changed file with 96 additions and 2 deletions.
98 changes: 96 additions & 2 deletions controllers/jupyterlab_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@ package controllers

import (
"context"
"reflect"
"testing"

toolsv1alpha1 "github.com/ministryofjustice/analytical-platform-tools-operator/api/v1alpha1"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

toolsv1alpha1 "github.com/ministryofjustice/analytical-platform-tools-operator/api/v1alpha1"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client"
)

var _ = Describe("JupyterLab controller", func() {
Expand Down Expand Up @@ -43,3 +49,91 @@ var _ = Describe("JupyterLab controller", func() {
})
})
})

func TestJupyterLabReconciler_deploymentForJupyterLab(t *testing.T) {
type fields struct {
Client client.Client
Scheme *runtime.Scheme
}
type args struct {
ctx context.Context
jupyterlab *toolsv1alpha1.JupyterLab
}
tests := []struct {
name string
fields fields
args args
want *appsv1.Deployment
}{
{
name: "should create a deployment for a JupyterLab",
fields: fields{
Client: k8sClient,
Scheme: scheme.Scheme,
},
args: args{
ctx: context.TODO(),
jupyterlab: &toolsv1alpha1.JupyterLab{
ObjectMeta: metav1.ObjectMeta{
Name: "test-jupyterlab",
Namespace: "default",
},
Spec: toolsv1alpha1.JupyterLabSpec{
Image: "jupyterlab/minimal",
Version: "latest",
},
},
},
want: &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "test-jupyterlab",
Namespace: "default",
Labels: map[string]string{
"app": "jupyter",
"chart": "test-jupyterlab",
"app.kubernetes.io/managed-by": "jupyterlab-operator",
"app.kubernetes.io/component": "jupyterlab",
"app.kubernetes.io/part-of": "jupyterlab",
"app.kubernetes.io/version": "latest",
},
},
Spec: appsv1.DeploymentSpec{
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{"app": "jupyterlab"},
},
Template: corev1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{"app": "jupyterlab"},
},
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "jupyterlab",
Image: "jupyterlab/minimal:latest",
Ports: []corev1.ContainerPort{
{
Name: "http",
Protocol: corev1.ProtocolTCP,
ContainerPort: 8888,
},
},
},
},
},
},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r := &JupyterLabReconciler{
Client: tt.fields.Client,
Scheme: tt.fields.Scheme,
}
if got := r.deploymentForJupyterLab(tt.args.ctx, tt.args.jupyterlab); !reflect.DeepEqual(got, tt.want) {
t.Errorf("JupyterLabReconciler.deploymentForJupyterLab() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit f2162b3

Please sign in to comment.