-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
support inline transformer and generator
- Loading branch information
1 parent
66221d1
commit d679d2b
Showing
2 changed files
with
103 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// Copyright 2019 The Kubernetes Authors. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package krusty_test | ||
|
||
import ( | ||
"testing" | ||
|
||
kusttest_test "sigs.k8s.io/kustomize/api/testutils/kusttest" | ||
) | ||
|
||
func TestInlineTransformer(t *testing.T) { | ||
th := kusttest_test.MakeEnhancedHarness(t) | ||
defer th.Reset() | ||
|
||
th.WriteF("/app/resource.yaml", ` | ||
apiVersion: apps/v1 | ||
kind: ConfigMap | ||
metadata: | ||
name: whatever | ||
data: {} | ||
`) | ||
th.WriteK("/app", ` | ||
resources: | ||
- resource.yaml | ||
transformers: | ||
- |- | ||
apiVersion: builtin | ||
kind: NamespaceTransformer | ||
metadata: | ||
name: not-important-to-example | ||
namespace: test | ||
fieldSpecs: | ||
- path: metadata/namespace | ||
create: true | ||
`) | ||
|
||
expected := ` | ||
apiVersion: apps/v1 | ||
data: {} | ||
kind: ConfigMap | ||
metadata: | ||
name: whatever | ||
namespace: test | ||
` | ||
|
||
m := th.Run("/app", th.MakeDefaultOptions()) | ||
th.AssertActualEqualsExpected(m, expected) | ||
} | ||
|
||
func TestInlineGenerator(t *testing.T) { | ||
th := kusttest_test.MakeEnhancedHarness(t) | ||
defer th.Reset() | ||
|
||
th.WriteK("/app", ` | ||
generators: | ||
- |- | ||
apiVersion: builtin | ||
kind: ConfigMapGenerator | ||
metadata: | ||
name: mymap | ||
literals: | ||
- FRUIT=apple | ||
- VEGETABLE=carrot | ||
`) | ||
|
||
expected := ` | ||
apiVersion: v1 | ||
data: | ||
FRUIT: apple | ||
VEGETABLE: carrot | ||
kind: ConfigMap | ||
metadata: | ||
name: mymap-kfd8tf729k | ||
` | ||
|
||
m := th.Run("/app", th.MakeDefaultOptions()) | ||
th.AssertActualEqualsExpected(m, expected) | ||
} |