Skip to content

Commit

Permalink
added simple kuttl and unit test to make sure the CRD can be applied
Browse files Browse the repository at this point in the history
Signed-off-by: Florian Bacher <[email protected]>
  • Loading branch information
bacherfl committed Mar 28, 2023
1 parent 18b330c commit f2e3351
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ type KeptnAppCreationRequestReconciler struct {

// Reconcile is part of the main kubernetes reconciliation loop which aims to
// move the current state of the cluster closer to the desired state.
// TODO(user): Modify the Reconcile function to compare the state specified by
// the KeptnAppCreationRequest object against the actual cluster state, and then
// perform operations to make the cluster state reflect the state specified by
// the user.
Expand All @@ -51,8 +50,6 @@ type KeptnAppCreationRequestReconciler struct {
func (r *KeptnAppCreationRequestReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
_ = log.FromContext(ctx)

// TODO(user): your logic here

return ctrl.Result{}, nil
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package keptnappcreationrequest

import (
"context"
"github.com/go-logr/logr"
klcv1alpha3 "github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha3"
"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
controllerruntime "sigs.k8s.io/controller-runtime"
k8sfake "sigs.k8s.io/controller-runtime/pkg/client/fake"
"testing"
)

func TestKeptnAppCreationRequestReconciler_Reconcile(t *testing.T) {
fakeClient := k8sfake.NewClientBuilder().WithObjects().Build()

err := klcv1alpha3.AddToScheme(fakeClient.Scheme())
require.Nil(t, err)

kacr := &klcv1alpha3.KeptnAppCreationRequest{
ObjectMeta: metav1.ObjectMeta{
Name: "my-kacr",
Namespace: "my-namespace",
},
Spec: klcv1alpha3.KeptnAppCreationRequestSpec{
AppName: "my-app",
},
}

err = fakeClient.Create(context.TODO(), kacr)
require.Nil(t, err)

r := &KeptnAppCreationRequestReconciler{
Client: fakeClient,
Scheme: fakeClient.Scheme(),
Log: logr.Logger{},
}

_, err = r.Reconcile(context.Background(), controllerruntime.Request{
NamespacedName: types.NamespacedName{
Namespace: kacr.Namespace,
Name: kacr.Name,
},
})

require.Nil(t, err)
}
6 changes: 6 additions & 0 deletions test/integration/app-creation-request/00-assert.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: lifecycle.keptn.sh/v1alpha3
kind: KeptnAppCreationRequest
metadata:
name: my-kacr
spec:
appName: my-app
6 changes: 6 additions & 0 deletions test/integration/app-creation-request/00-install.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
apiVersion: lifecycle.keptn.sh/v1alpha3
kind: KeptnAppCreationRequest
metadata:
name: my-kacr
spec:
appName: my-app

0 comments on commit f2e3351

Please sign in to comment.