Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add test case
  • Loading branch information
akrantz01 committed Dec 23, 2021
commit 9280ad9911c9ae0a9597c8b9fa0027245e8f0fe2
40 changes: 28 additions & 12 deletions tests/crds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,38 @@ import (
"github.com/stretchr/testify/assert"
)

// TestCRDs enumerates all CRD YAML files, and generates them in each language.
func TestCRDs(t *testing.T) {
var languages = []string{"dotnet", "go", "nodejs", "python"}

const gkeManagedCertsUrl = "https://raw.githubusercontent.com/GoogleCloudPlatform/gke-managed-certs/master/deploy/managedcertificates-crd.yaml"

// execCrd2Pulumi runs the crd2pulumi binary in a temporary directory
func execCrd2Pulumi(t *testing.T, lang, path string) {
tmpdir, err := ioutil.TempDir("", "")
assert.Nil(t, err, "expected to create a temp dir for the CRD output")
defer os.RemoveAll(tmpdir)
langFlag := "--" + lang + "Path"
t.Logf("crd2pulumi %s=%s %s: running", langFlag, tmpdir, path)
crdCmd := exec.Command("crd2pulumi", langFlag, tmpdir, "--force", path)
crdOut, err := crdCmd.CombinedOutput()
t.Logf("crd2pulumi %s=%s %s: output=\n%s", langFlag, tmpdir, path, crdOut)
assert.Nil(t, err, "expected crd2pulumi for '%s=%s %s' to succeed", langFlag, tmpdir, path)
}

// TestCRDsFromFile enumerates all CRD YAML files, and generates them in each language.
func TestCRDsFromFile(t *testing.T) {
filepath.WalkDir("crds", func(path string, d fs.DirEntry, err error) error {
if !d.IsDir() && (filepath.Ext(path) == ".yml" || filepath.Ext(path) == ".yaml") {
for _, lang := range []string{"dotnet", "go", "nodejs", "python"} {
tmpdir, err := ioutil.TempDir("", "")
assert.Nil(t, err, "expected to create a temp dir for the CRD output")
defer os.RemoveAll(tmpdir)
langFlag := "--" + lang + "Path"
t.Logf("crd2pulumi %s=%s %s: running", langFlag, tmpdir, path)
crdCmd := exec.Command("crd2pulumi", langFlag, tmpdir, "--force", path)
crdOut, err := crdCmd.CombinedOutput()
t.Logf("crd2pulumi %s=%s %s: output=\n%s", langFlag, tmpdir, path, crdOut)
assert.Nil(t, err, "expected crd2pulumi for '%s=%s %s' to succeed", langFlag, tmpdir, path)
for _, lang := range languages {
execCrd2Pulumi(t, lang, path)
}
}
return nil
})
}

// TestCRDsFromUrl pulls the CRD YAML file from a URL and generates it in each language
func TestCRDsFromUrl(t *testing.T) {
for _, lang := range languages {
execCrd2Pulumi(t, lang, gkeManagedCertsUrl)
}
}