From 06dfe8c729b3c3b38ac6f1886e322f8cbca2ce01 Mon Sep 17 00:00:00 2001 From: Ramon Quitales Date: Thu, 12 Sep 2024 12:49:43 -0700 Subject: [PATCH] Add more regression testing and compilation steps --- tests/crds_test.go | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tests/crds_test.go b/tests/crds_test.go index 72078e2..8f4e414 100644 --- a/tests/crds_test.go +++ b/tests/crds_test.go @@ -78,6 +78,29 @@ func TestCRDsFromFile(t *testing.T) { // TestCRDsFromUrl pulls the CRD YAML file from a URL and generates it in each language func TestCRDsFromUrl(t *testing.T) { + validateNodeCompiles := func(t *testing.T, path string) { + withDir(t, path, func() { + runRequireNoError(t, exec.Command("npm", "install")) + runRequireNoError(t, exec.Command("npm", "run", "build")) + }) + } + + validateGolangCompiles := func(t *testing.T, path string) { + withDir(t, path, func() { + runRequireNoError(t, exec.Command("go", "mod", "init", "fakepackage")) + runRequireNoError(t, exec.Command("go", "mod", "tidy")) + runRequireNoError(t, exec.Command("go", "vet", "./...")) + }) + } + + compileValidationFn := map[string]func(t *testing.T, path string){ + "nodejs": validateNodeCompiles, + "go": validateGolangCompiles, + "python": nil, + "java": nil, + "dotnet": nil, + } + tests := []struct { name string url string @@ -98,6 +121,16 @@ func TestCRDsFromUrl(t *testing.T) { name: "Contours", url: "https://raw.githubusercontent.com/projectcontour/contour-operator/f8c07498803d062e30c255976270cbc82cd619b0/config/crd/bases/operator.projectcontour.io_contours.yaml", }, + { + // https://github.com/pulumi/crd2pulumi/issues/141 + name: "ElementDeployment", + url: "https://raw.githubusercontent.com/element-hq/ess-starter-edition-core/d7e792bf8a872f06f02f59d807a1c16ee933862b/roles/elementdeployment/files/elementdeployment-schema.yaml", + }, + { + // https://github.com/pulumi/crd2pulumi/issues/142 + name: "Keycloak", + url: "https://raw.githubusercontent.com/keycloak/keycloak-k8s-resources/25.0.4/kubernetes/keycloaks.k8s.keycloak.org-v1.yml", + }, } for _, tt := range tests { @@ -106,7 +139,7 @@ func TestCRDsFromUrl(t *testing.T) { lang := lang t.Run(lang, func(t *testing.T) { t.Parallel() - execCrd2Pulumi(t, lang, tt.url, nil) + execCrd2Pulumi(t, lang, tt.url, compileValidationFn[lang]) }) } })