Skip to content

Commit

Permalink
Tests for updating the GitOps templates.
Browse files Browse the repository at this point in the history
Further tests for the GitOps templates.
  • Loading branch information
bigkevmcd committed Mar 13, 2023
1 parent 3f69119 commit 16ff757
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 1 deletion.
62 changes: 61 additions & 1 deletion controllers/capitemplate_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,11 @@ import (
capiv1alpha1 "github.com/weaveworks/templates-controller/apis/capi/v1alpha1"
capiv1alpha2 "github.com/weaveworks/templates-controller/apis/capi/v1alpha2"
"github.com/weaveworks/templates-controller/apis/core"
gitopsv1alpha1 "github.com/weaveworks/templates-controller/apis/gitops/v1alpha1"
gitopsv1alpha2 "github.com/weaveworks/templates-controller/apis/gitops/v1alpha2"
)

func TestCAPITemplateConversion(t *testing.T) {
func TestCAPITemplateV1Alpha1Conversion(t *testing.T) {
ctx := context.TODO()

ct := &capiv1alpha1.CAPITemplate{
Expand Down Expand Up @@ -73,6 +75,64 @@ func TestCAPITemplateConversion(t *testing.T) {
}
}

func TestGitOpsTemplateV1Alpha1Conversion(t *testing.T) {
ctx := context.TODO()

ct := &gitopsv1alpha1.GitOpsTemplate{
ObjectMeta: metav1.ObjectMeta{
Name: "test-template",
Namespace: "default",
},
TypeMeta: metav1.TypeMeta{
Kind: capiv1alpha1.Kind,
APIVersion: "capi.weave.works/v1alpha1",
},
Spec: core.TemplateSpecV1{
Description: "this is test template 1",
Params: []core.TemplateParam{
{
Name: "CLUSTER_NAME",
Description: "This is used for the cluster naming.",
Required: false,
},
},
},
}

assertNoError(t, testEnv.Create(ctx, ct))
defer cleanupResource(t, testEnv, ct)

updated := &gitopsv1alpha2.GitOpsTemplate{}
assertNoError(t, testEnv.Get(ctx, client.ObjectKeyFromObject(ct), updated))

want := &gitopsv1alpha2.GitOpsTemplate{
ObjectMeta: metav1.ObjectMeta{
Name: "test-template",
Namespace: "default",
},
TypeMeta: metav1.TypeMeta{
Kind: gitopsv1alpha2.Kind,
APIVersion: "templates.weave.works/v1alpha2",
},
Spec: core.TemplateSpec{
Description: "this is test template 1",
RenderType: "envsubst",
Params: []core.TemplateParam{
{
Name: "CLUSTER_NAME",
Description: "This is used for the cluster naming.",
Required: false,
},
},
ResourceTemplates: []core.ResourceTemplate{{}},
},
}

if diff := cmp.Diff(want, updated, ignoreObjectMeta); diff != "" {
t.Fatalf("failed to update the template:\n%s\n", diff)
}
}

var ignoreObjectMeta = cmpopts.IgnoreFields(metav1.ObjectMeta{}, "ResourceVersion", "UID", "Generation", "CreationTimestamp", "ManagedFields")

func cleanupResource(t *testing.T, cl client.Client, obj client.Object) {
Expand Down
4 changes: 4 additions & 0 deletions controllers/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import (

capiv1alpha1 "github.com/weaveworks/templates-controller/apis/capi/v1alpha1"
capiv1alpha2 "github.com/weaveworks/templates-controller/apis/capi/v1alpha2"
gitopsv1alpha1 "github.com/weaveworks/templates-controller/apis/gitops/v1alpha1"
gitopsv1alpha2 "github.com/weaveworks/templates-controller/apis/gitops/v1alpha2"
)

var (
Expand All @@ -29,6 +31,8 @@ func init() {
func TestMain(m *testing.M) {
utilruntime.Must(capiv1alpha1.AddToScheme(scheme.Scheme))
utilruntime.Must(capiv1alpha2.AddToScheme(scheme.Scheme))
utilruntime.Must(gitopsv1alpha1.AddToScheme(scheme.Scheme))
utilruntime.Must(gitopsv1alpha2.AddToScheme(scheme.Scheme))
testEnv = testenv.New(testenv.WithCRDPath(filepath.Join("..", "config", "crd", "bases")))

if err := (&CAPITemplateReconciler{
Expand Down

0 comments on commit 16ff757

Please sign in to comment.