mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
Enable logging in runfn
This commit is contained in:
@@ -14,6 +14,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"sigs.k8s.io/kustomize/kyaml/copyutil"
|
||||
"sigs.k8s.io/kustomize/kyaml/errors"
|
||||
"sigs.k8s.io/kustomize/kyaml/fn/runtime/container"
|
||||
@@ -906,6 +907,36 @@ func TestCmd_Execute_setInput(t *testing.T) {
|
||||
assert.Contains(t, string(b), "kind: StatefulSet")
|
||||
}
|
||||
|
||||
// TestCmd_Execute_enableLogSteps tests the execution of a filter with LogSteps enabled.
|
||||
func TestCmd_Execute_enableLogSteps(t *testing.T) {
|
||||
dir := setupTest(t)
|
||||
defer os.RemoveAll(dir)
|
||||
|
||||
// write a test filter to the directory of configuration
|
||||
if !assert.NoError(t, ioutil.WriteFile(
|
||||
filepath.Join(dir, "filter.yaml"), []byte(ValueReplacerYAMLData), 0600)) {
|
||||
return
|
||||
}
|
||||
|
||||
logs := &bytes.Buffer{}
|
||||
instance := RunFns{
|
||||
Path: dir,
|
||||
functionFilterProvider: getFilterProvider(t),
|
||||
LogSteps: true,
|
||||
LogWriter: logs,
|
||||
}
|
||||
if !assert.NoError(t, instance.Execute()) {
|
||||
t.FailNow()
|
||||
}
|
||||
b, err := ioutil.ReadFile(
|
||||
filepath.Join(dir, "java", "java-deployment.resource.yaml"))
|
||||
if !assert.NoError(t, err) {
|
||||
t.FailNow()
|
||||
}
|
||||
assert.Contains(t, string(b), "kind: StatefulSet")
|
||||
assert.Equal(t, "Running unknown-type function\n", logs.String())
|
||||
}
|
||||
|
||||
// setupTest initializes a temp test directory containing test data
|
||||
func setupTest(t *testing.T) string {
|
||||
dir, err := ioutil.TempDir("", "kustomize-kyaml-test")
|
||||
|
||||
Reference in New Issue
Block a user