1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73
|
// +build notravis
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
package main_test
import (
"strings"
"testing"
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest"
)
func TestValidatorHappy(t *testing.T) {
th := kusttest_test.MakeEnhancedHarness(t).
PrepExecPlugin("someteam.example.com", "v1", "Validator")
defer th.Reset()
rm := th.LoadAndRunTransformer(`
apiVersion: someteam.example.com/v1
kind: Validator
metadata:
name: notImportantHere
`,
`apiVersion: v1
kind: ConfigMap
metadata:
annotations:
foo: bar
name: some-cm
data:
foo: bar
`)
th.AssertActualEqualsExpected(rm, `
apiVersion: v1
data:
foo: bar
kind: ConfigMap
metadata:
annotations:
foo: bar
name: some-cm
`)
}
func TestValidatorUnHappy(t *testing.T) {
th := kusttest_test.MakeEnhancedHarness(t).
PrepExecPlugin("someteam.example.com", "v1", "Validator")
defer th.Reset()
err := th.ErrorFromLoadAndRunTransformer(`
apiVersion: someteam.example.com/v1
kind: Validator
metadata:
name: notImportantHere
`,
`apiVersion: v1
kind: ConfigMap
metadata:
annotations: {}
name: some-cm
data:
- foo: bar
`)
if err == nil {
t.Fatalf("expected an error")
}
if !strings.Contains(err.Error(), "failure in plugin configured via") {
t.Fatalf("unexpected error: %v", err)
}
}
|