Newer
Older
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"orus.io/cloudcrane/beaver/testutils"
)
func TestConfig(t *testing.T) {
require.NoError(t, err)
// first config.spec.variables entry name should be VAULT_KV in our test file
assert.Equal(t, "VAULT_KV", config.Spec.Variables[0].Name)
assert.Equal(t, "orus.io", config.Spec.Variables[0].Value)
assert.Equal(t, "vendor/helm/postgresql", config.Spec.Charts["postgres"].Path)
assert.Equal(t, "vendor/ytt/odoo", config.Spec.Charts["odoo"].Path)
func TestNamespaceConfigNotMandatory(t *testing.T) {
_, err := runner.NewConfig(secondFixtures)
require.NoError(t, err)
}
func TestYttBuildArgs(t *testing.T) {
tl := testutils.NewTestLogger(t)
testNS := "ns1"
require.NoError(t, err)
c := runner.NewCmdConfig(tl.Logger(), absConfigDir, testNS, false)
tmpDir, err := os.MkdirTemp(os.TempDir(), "beaver-")
require.NoError(t, err)
defer func() {
assert.NoError(t, os.RemoveAll(tmpDir))
}()
require.NoError(t, c.Initialize(tmpDir))
args := c.Spec.Ytt.BuildArgs(fixtures, testNS, []string{"/tmp/postgres.1234.yaml", "/tmp/odoo.5678.yaml"})
[]string{
"-f", "/tmp/postgres.1234.yaml", "--file-mark=postgres.1234.yaml:type=yaml-plain",
"-f", "/tmp/odoo.5678.yaml", "--file-mark=odoo.5678.yaml:type=yaml-plain",
"-f", filepath.Join(fixtures, "base/ytt"),
"-f", filepath.Join(fixtures, "base/ytt.yml"),
"-f", filepath.Join(fixtures, "environments/ns1/ytt"),
"-f", filepath.Join(fixtures, "environments/ns1/ytt.yaml"),
func TestCreateConfig(t *testing.T) {
tl := testutils.NewTestLogger(t)
testNS := "ns1"
absConfigDir, err := filepath.Abs(fixtures)
require.NoError(t, err)
c := runner.NewCmdConfig(tl.Logger(), absConfigDir, testNS, false)
tmpDir, err := os.MkdirTemp(os.TempDir(), "beaver-")
require.NoError(t, err)
defer func() {
assert.NoError(t, os.RemoveAll(tmpDir))
}()
require.NoError(t, c.Initialize(tmpDir))
require.Equal(t, 1, len(c.Spec.Creates))
for k, a := range c.Spec.Creates {
args := k.BuildArgs(c.Namespace, a)
assert.Equal(
t,
[]string{
"-n", c.Namespace,
"create",
"configmap", "xbus-pipelines",
"--dry-run=client", "-o", "yaml",
"--from-file", "environments/ns1/pipelines",
},
args,
)
}
}