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
Refactor tests
  • Loading branch information
rquitales committed May 25, 2023
commit a47fea29190c16914bd8a31120945960fc33316e
26 changes: 20 additions & 6 deletions tests/crds_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package tests

import (
"fmt"
"io/fs"
"io/ioutil"
"os"
Expand All @@ -31,14 +32,18 @@ const gkeManagedCertsUrl = "https://raw.githubusercontent.com/GoogleCloudPlatfor

// execCrd2Pulumi runs the crd2pulumi binary in a temporary directory
func execCrd2Pulumi(t *testing.T, lang, path string) {
tmpdir, err := ioutil.TempDir("", "")
tmpdir, err := ioutil.TempDir("", "crd2pulumi_test")
assert.Nil(t, err, "expected to create a temp dir for the CRD output")
defer os.RemoveAll(tmpdir)
langFlag := "--" + lang + "Path"
t.Cleanup(func() {
t.Logf("removing temp dir %q for %s test", tmpdir, lang)
os.RemoveAll(tmpdir)
})
langFlag := fmt.Sprintf("--%sPath", lang) // e.g. --dotnetPath
binaryPath, err := filepath.Abs("../bin/crd2pulumi")
if err != nil {
panic(err)
t.Fatalf("unable to create absolute path to binary: %s", err)
}

t.Logf("%s %s=%s %s: running", binaryPath, langFlag, tmpdir, path)
crdCmd := exec.Command(binaryPath, langFlag, tmpdir, "--force", path)
crdOut, err := crdCmd.CombinedOutput()
Expand All @@ -51,7 +56,12 @@ 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 languages {
execCrd2Pulumi(t, lang, path)
lang := lang
name := fmt.Sprintf("%s-%s", lang, filepath.Base(path))
t.Run(name, func(t *testing.T) {
t.Parallel()
execCrd2Pulumi(t, lang, path)
})
}
}
return nil
Expand All @@ -61,6 +71,10 @@ 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) {
for _, lang := range languages {
execCrd2Pulumi(t, lang, gkeManagedCertsUrl)
lang := lang
t.Run(lang, func(t *testing.T) {
t.Parallel()
execCrd2Pulumi(t, lang, gkeManagedCertsUrl)
})
}
}