diff --git a/pkg/tanka/export_test.go b/pkg/tanka/export_test.go index ae9e4b8f0..7bf000d8b 100644 --- a/pkg/tanka/export_test.go +++ b/pkg/tanka/export_test.go @@ -7,6 +7,7 @@ import ( "testing" "github.com/grafana/tanka/pkg/jsonnet" + "github.com/grafana/tanka/pkg/kubernetes/manifest" "github.com/rs/zerolog" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" @@ -142,6 +143,25 @@ func TestExportEnvironments(t *testing.T) { }`) } +func TestExportEnvironmentsBroken(t *testing.T) { + tempDir := t.TempDir() + require.NoError(t, os.Chdir("testdata")) + defer func() { require.NoError(t, os.Chdir("..")) }() + + // Find envs + envs, err := FindEnvs("test-export-envs-broken", FindOpts{Selector: labels.Everything()}) + require.NoError(t, err) + + // Export all envs + opts := &ExportEnvOpts{ + Format: "{{.metadata.namespace}}/{{.metadata.name}}", + Extension: "yaml", + } + + var schemaError *manifest.SchemaError + require.ErrorAs(t, ExportEnvironments(envs, tempDir, opts), &schemaError) +} + func BenchmarkExportEnvironmentsWithReplaceEnvs(b *testing.B) { zerolog.SetGlobalLevel(zerolog.Disabled) tempDir := b.TempDir() diff --git a/pkg/tanka/testdata/test-export-envs-broken/static-env/main.jsonnet b/pkg/tanka/testdata/test-export-envs-broken/static-env/main.jsonnet new file mode 100644 index 000000000..76df07e05 --- /dev/null +++ b/pkg/tanka/testdata/test-export-envs-broken/static-env/main.jsonnet @@ -0,0 +1,17 @@ +{ + deployment: { + apiVersion: 'apps/v1', + kind: 'Deployment', + metadata: { + name: 'foo', + }, + }, + service: { + apiVersion: 'v1', + kind: 'Service', + metadata: { + // Error, this should be a string + name: true, + }, + }, +} diff --git a/pkg/tanka/testdata/test-export-envs-broken/static-env/spec.json b/pkg/tanka/testdata/test-export-envs-broken/static-env/spec.json new file mode 100644 index 000000000..52f9f8309 --- /dev/null +++ b/pkg/tanka/testdata/test-export-envs-broken/static-env/spec.json @@ -0,0 +1,14 @@ +{ + "apiVersion": "tanka.dev/v1alpha1", + "kind": "Environment", + "metadata": { + "name": "static", + "labels": { + "type": "static" + } + }, + "spec": { + "apiServer": "https://localhost", + "namespace": "static" + } +}