From f7f686544190265db41a2af7bd3313f94d67c880 Mon Sep 17 00:00:00 2001 From: Elad Kaplan Date: Wed, 20 Jul 2022 12:23:23 +0300 Subject: [PATCH] move porcelain to stderr (#124) move porcelain to stderr --- e2e/e2e_test.go | 8 +++++++- e2e/tests/custom-config-file.yml | 4 ++-- e2e/tests/delete.yml | 4 ++-- e2e/tests/put-sync.yml | 4 ++-- e2e/tests/put.yml | 4 ++-- e2e/tests/scan.yml | 3 +-- e2e/tests/show.yml | 4 ++-- e2e/testutils/config.go | 21 +++++++++++---------- pkg/teller.go | 2 +- 9 files changed, 30 insertions(+), 24 deletions(-) diff --git a/e2e/e2e_test.go b/e2e/e2e_test.go index 9f978754..202158e0 100644 --- a/e2e/e2e_test.go +++ b/e2e/e2e_test.go @@ -23,7 +23,7 @@ const ( testsFolder = "tests" ) -func TestE2E(t *testing.T) { +func TestE2E(t *testing.T) { //nolint t.Parallel() // validate given binary path @@ -75,6 +75,12 @@ func TestE2E(t *testing.T) { stdout = re.ReplaceAllString(stdout, r.Replace) } } + if len(snapshot.ReplaceStdErrContent) > 0 { + for _, r := range snapshot.ReplaceStdErrContent { + var re = regexp.MustCompile(r.Search) + stderr = re.ReplaceAllString(stderr, r.Replace) + } + } if snapshot.ExpectedStdOut != "" { assert.Equal(t, snapshot.ExpectedStdOut, stdout) diff --git a/e2e/tests/custom-config-file.yml b/e2e/tests/custom-config-file.yml index 185502af..e75e41f8 100644 --- a/e2e/tests/custom-config-file.yml +++ b/e2e/tests/custom-config-file.yml @@ -15,9 +15,9 @@ init_snapshot: file_name: foo content: shazam expected_snapshot: -expected_stdout: | +expected_stderr: | -*- teller: loaded variables for test using .custom-teller.yml -*- [filesystem DYNAMIC-SHORT-PATH...tings/test/foo] FOO = sh***** -expected_stderr: \ No newline at end of file +expected_stdout: \ No newline at end of file diff --git a/e2e/tests/delete.yml b/e2e/tests/delete.yml index 8c92b021..dfdfdf51 100644 --- a/e2e/tests/delete.yml +++ b/e2e/tests/delete.yml @@ -41,8 +41,8 @@ expected_snapshot: file_name: secret-c content: shazam-1 -expected_stdout: | +expected_stderr: | Delete FOO (DYNAMIC-FULL-PATH/settings/test/foo) in filesystem: OK. Delete BAR (DYNAMIC-FULL-PATH/settings/test/bar) in filesystem: OK. -expected_stderr: \ No newline at end of file +expected_stdout: \ No newline at end of file diff --git a/e2e/tests/put-sync.yml b/e2e/tests/put-sync.yml index 1977be50..680fbacb 100644 --- a/e2e/tests/put-sync.yml +++ b/e2e/tests/put-sync.yml @@ -52,7 +52,7 @@ expected_snapshot: - path: settings/test/all file_name: key-2 content: key-2-content -expected_stdout: | +expected_stderr: | Synced filesystem (DYNAMIC-FULL-PATH/settings/test/all): OK. -expected_stderr: \ No newline at end of file +expected_stdout: \ No newline at end of file diff --git a/e2e/tests/put.yml b/e2e/tests/put.yml index 5d0e4224..ec3b400d 100644 --- a/e2e/tests/put.yml +++ b/e2e/tests/put.yml @@ -46,8 +46,8 @@ expected_snapshot: - path: settings/test/all file_name: secret-c content: shazam-1 -expected_stdout: | +expected_stderr: | Put BAR (DYNAMIC-FULL-PATH/settings/test/bar) in filesystem: OK. Put FOO (DYNAMIC-FULL-PATH/settings/test/foo) in filesystem: OK. -expected_stderr: \ No newline at end of file +expected_stdout: \ No newline at end of file diff --git a/e2e/tests/scan.yml b/e2e/tests/scan.yml index 0045b399..5774d2dc 100644 --- a/e2e/tests/scan.yml +++ b/e2e/tests/scan.yml @@ -4,7 +4,7 @@ command: scan config_file_name: .teller.yml config_content: > project: test - + providers: filesystem: env_sync: @@ -47,6 +47,5 @@ expected_stdout: | [high] settings/test/foo (1,0): found match for filesystem/secret-b (sh*****) [low] settings/test/foo (1,0): found match for filesystem/FOO (sh*****) [medium] settings/test/foo (1,0): found match for filesystem/BAR (sh*****) - Scanning for 4 entries: found 10 matches in 1.000ms expected_stderr: \ No newline at end of file diff --git a/e2e/tests/show.yml b/e2e/tests/show.yml index db64e893..bbe49baa 100644 --- a/e2e/tests/show.yml +++ b/e2e/tests/show.yml @@ -31,7 +31,7 @@ init_snapshot: file_name: secret-c content: shazam-1 expected_snapshot: -expected_stdout: | +expected_stderr: | -*- teller: loaded variables for test using .teller.yml -*- [filesystem DYNAMIC-SHORT-PATH...tings/test/bar] BAR = sh***** @@ -40,4 +40,4 @@ expected_stdout: | [filesystem DYNAMIC-SHORT-PATH...tings/test/all] secret-b = sh***** [filesystem DYNAMIC-SHORT-PATH...tings/test/all] secret-c = sh***** -expected_stderr: \ No newline at end of file +expected_stdout: \ No newline at end of file diff --git a/e2e/testutils/config.go b/e2e/testutils/config.go index 811decba..d28f4ae8 100644 --- a/e2e/testutils/config.go +++ b/e2e/testutils/config.go @@ -11,15 +11,16 @@ import ( ) type SnapshotSuite struct { - Name string `yaml:"name,omitempty"` - Command string `yaml:"command,omitempty"` - ConfigFileName string `yaml:"config_file_name,omitempty"` - Config string `yaml:"config_content,omitempty"` - InitSnapshot []SnapshotData `yaml:"init_snapshot,omitempty"` - ExpectedSnapshot []SnapshotData `yaml:"expected_snapshot,omitempty"` - ExpectedStdOut string `yaml:"expected_stdout,omitempty"` - ExpectedStdErr string `yaml:"expected_stderr,omitempty"` - ReplaceStdOutContent []ReplaceStdOutContent `yaml:"replace_stdout_content,omitempty"` + Name string `yaml:"name,omitempty"` + Command string `yaml:"command,omitempty"` + ConfigFileName string `yaml:"config_file_name,omitempty"` + Config string `yaml:"config_content,omitempty"` + InitSnapshot []SnapshotData `yaml:"init_snapshot,omitempty"` + ExpectedSnapshot []SnapshotData `yaml:"expected_snapshot,omitempty"` + ExpectedStdOut string `yaml:"expected_stdout,omitempty"` + ExpectedStdErr string `yaml:"expected_stderr,omitempty"` + ReplaceStdOutContent []ReplaceStdContent `yaml:"replace_stdout_content,omitempty"` + ReplaceStdErrContent []ReplaceStdContent `yaml:"replace_stderr_content,omitempty"` } type SnapshotData struct { @@ -28,7 +29,7 @@ type SnapshotData struct { Content string `yaml:"content"` } -type ReplaceStdOutContent struct { +type ReplaceStdContent struct { Search string `yaml:"search"` Replace string `yaml:"replace"` } diff --git a/pkg/teller.go b/pkg/teller.go index 9c3af828..bab42925 100644 --- a/pkg/teller.go +++ b/pkg/teller.go @@ -49,7 +49,7 @@ func NewTeller(tlrfile *TellerFile, cmd []string, redact bool, logger logging.Lo Cmd: cmd, Providers: &BuiltinProviders{}, Populate: core.NewPopulate(tlrfile.Opts), - Porcelain: &Porcelain{Out: os.Stdout}, + Porcelain: &Porcelain{Out: os.Stderr}, Templating: &Templating{}, Redactor: &Redactor{}, Logger: logger,