Skip to content

Commit

Permalink
export: Add test to check that invalid Kubernetes manifests produce a…
Browse files Browse the repository at this point in the history
… proper error

Currently fails, to be fixed in the next commit
  • Loading branch information
iainlane committed Dec 5, 2023
1 parent 865b186 commit 9f21bbe
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pkg/tanka/export_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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()
Expand Down
17 changes: 17 additions & 0 deletions pkg/tanka/testdata/test-export-envs-broken/static-env/main.jsonnet
Original file line number Diff line number Diff line change
@@ -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,
},
},
}
14 changes: 14 additions & 0 deletions pkg/tanka/testdata/test-export-envs-broken/static-env/spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"apiVersion": "tanka.dev/v1alpha1",
"kind": "Environment",
"metadata": {
"name": "static",
"labels": {
"type": "static"
}
},
"spec": {
"apiServer": "https://localhost",
"namespace": "static"
}
}

0 comments on commit 9f21bbe

Please sign in to comment.