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