Skip to content

Commit

Permalink
test: add bundle files test
Browse files Browse the repository at this point in the history
  • Loading branch information
b4nst committed Jun 29, 2023
1 parent 29e4757 commit 5edc239
Showing 1 changed file with 45 additions and 15 deletions.
60 changes: 45 additions & 15 deletions cmd/timoni/bundle_build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ package main

import (
"fmt"
"os"
"path/filepath"
"io/ioutil"
"strings"
"testing"

Expand Down Expand Up @@ -31,41 +30,72 @@ func Test_BundleBuild(t *testing.T) {
))
g.Expect(err).ToNot(HaveOccurred())

bundleData := fmt.Sprintf(`
bundleCue := fmt.Sprintf(`
bundle: {
apiVersion: "v1alpha1"
name: "%[1]s"
name: string
instances: {
frontend: {
module: {
url: "oci://%[2]s"
version: "%[3]s"
url: "oci://%[1]s"
version: "%[2]s"
}
namespace: "%[4]s"
namespace: string
values: server: enabled: false
}
backend: {
module: {
url: "oci://%[2]s"
version: "%[3]s"
url: "oci://%[1]s"
version: "%[2]s"
}
namespace: "%[4]s"
namespace: "%[3]s"
values: client: enabled: false
}
}
}
`, bundleName, modURL, modVer, namespace)
`, modURL, modVer, namespace)

bundlePath := filepath.Join(t.TempDir(), "bundle.cue")
err = os.WriteFile(bundlePath, []byte(bundleData), 0644)
bundleData := bundleCue + fmt.Sprintf(`
bundle: name: "%[1]s"
bundle: instances: frontend: namespace: "%[2]s"
`, bundleName, namespace)

bundleJson := fmt.Sprintf(`
{
"bundle": {
"name": "%[1]s"
}
}
`, bundleName)

bundleYaml := fmt.Sprintf(`
bundle:
instances:
frontend:
namespace: %[1]s
`, namespace)

cuef, err := ioutil.TempFile(t.TempDir(), "*.cue")
g.Expect(err).ToNot(HaveOccurred())
_, err = cuef.Write([]byte(bundleCue))
g.Expect(err).ToNot(HaveOccurred())

yamlf, err := ioutil.TempFile(t.TempDir(), "*.yaml")
g.Expect(err).ToNot(HaveOccurred())
_, err = yamlf.Write([]byte(bundleYaml))
g.Expect(err).ToNot(HaveOccurred())

jsonf, err := ioutil.TempFile(t.TempDir(), "*.json")
g.Expect(err).ToNot(HaveOccurred())
_, err = jsonf.Write([]byte(bundleJson))
g.Expect(err).ToNot(HaveOccurred())

t.Run("builds instances from bundle", func(t *testing.T) {
execCommands := map[string]func() (string, error){
"using a file": func() (string, error) {
return executeCommand(fmt.Sprintf(
"bundle build -f %s -p main",
bundlePath,
"bundle build -f %s -f %s -f %s -p main",
cuef.Name(), yamlf.Name(), jsonf.Name(),
))
},
"using stdin": func() (string, error) {
Expand Down

0 comments on commit 5edc239

Please sign in to comment.