From 99b261f3f9746c672028d8d0be792bf5babb23c1 Mon Sep 17 00:00:00 2001 From: Christian Winther Date: Thu, 15 Feb 2024 01:52:09 +0100 Subject: [PATCH] more tests for print --- cmd/print/prin_test.go | 2 +- cmd/print/print.go | 2 +- cmd/print/tests/empty.command.txt | 1 + cmd/print/tests/empty/env.golden | 0 cmd/print/tests/empty/stdout.golden | 2 ++ cmd/print/tests/full.command.txt | 1 + cmd/print/tests/full/stdout.golden | 31 +++++++++++++++++++ cmd/print/tests/simple-pretty.command.txt | 1 + .../stdout.golden} | 2 +- cmd/print/tests/simple.command.txt | 1 + .../env.golden => simple/stdout.golden} | 4 +-- cmd/print/tests/specific-group.command.txt | 3 ++ .../{full/env.golden => specific-group.env} | 0 cmd/print/tests/specific-group/stdout.golden | 4 +++ 14 files changed, 48 insertions(+), 6 deletions(-) delete mode 100644 cmd/print/tests/empty/env.golden create mode 100644 cmd/print/tests/empty/stdout.golden create mode 100644 cmd/print/tests/full/stdout.golden rename cmd/print/tests/{simple/env.golden => simple-pretty/stdout.golden} (72%) rename cmd/print/tests/{simple-pretty/env.golden => simple/stdout.golden} (72%) create mode 100644 cmd/print/tests/specific-group.command.txt rename cmd/print/tests/{full/env.golden => specific-group.env} (100%) create mode 100644 cmd/print/tests/specific-group/stdout.golden diff --git a/cmd/print/prin_test.go b/cmd/print/prin_test.go index ee206ac..937c571 100644 --- a/cmd/print/prin_test.go +++ b/cmd/print/prin_test.go @@ -9,5 +9,5 @@ import ( func TestCommand(t *testing.T) { t.Parallel() - test_helpers.RunFilebasedCommandTests(t, 0, "print") + test_helpers.RunFilebasedCommandTests(t, test_helpers.SkipEnvCopy, "print") } diff --git a/cmd/print/print.go b/cmd/print/print.go index 89bcf7f..6c505e0 100644 --- a/cmd/print/print.go +++ b/cmd/print/print.go @@ -27,7 +27,7 @@ func NewCommand() *cobra.Command { return err } - fmt.Println(render.NewRenderer(*settings).Statement(env).String()) + fmt.Fprintln(cmd.OutOrStdout(), render.NewRenderer(*settings).Statement(env).String()) return nil }, diff --git a/cmd/print/tests/empty.command.txt b/cmd/print/tests/empty.command.txt index e69de29..6150730 100644 --- a/cmd/print/tests/empty.command.txt +++ b/cmd/print/tests/empty.command.txt @@ -0,0 +1 @@ +--no-color diff --git a/cmd/print/tests/empty/env.golden b/cmd/print/tests/empty/env.golden deleted file mode 100644 index e69de29..0000000 diff --git a/cmd/print/tests/empty/stdout.golden b/cmd/print/tests/empty/stdout.golden new file mode 100644 index 0000000..139597f --- /dev/null +++ b/cmd/print/tests/empty/stdout.golden @@ -0,0 +1,2 @@ + + diff --git a/cmd/print/tests/full.command.txt b/cmd/print/tests/full.command.txt index 11151ae..89701d5 100644 --- a/cmd/print/tests/full.command.txt +++ b/cmd/print/tests/full.command.txt @@ -1 +1,2 @@ --pretty +--no-color diff --git a/cmd/print/tests/full/stdout.golden b/cmd/print/tests/full/stdout.golden new file mode 100644 index 0000000..37e14d0 --- /dev/null +++ b/cmd/print/tests/full/stdout.golden @@ -0,0 +1,31 @@ +################################################################################ +# My first group +################################################################################ + +KEY_A="I'm key A" + +# Comment for KEY_B +KEY_B="I'm key B" + +KEY_C="I'm key C" + +################################################################################ +# My Second group +################################################################################ + +GROUP_TWO_A="hello" + +# This is nice, format me +GROUP_TWO_A="WORLD" + +################################################################################ +# My Third group +################################################################################ + +# A Comment + +# Another comment +# with two lines + +SECRET=KEY + diff --git a/cmd/print/tests/simple-pretty.command.txt b/cmd/print/tests/simple-pretty.command.txt index e69de29..6150730 100644 --- a/cmd/print/tests/simple-pretty.command.txt +++ b/cmd/print/tests/simple-pretty.command.txt @@ -0,0 +1 @@ +--no-color diff --git a/cmd/print/tests/simple/env.golden b/cmd/print/tests/simple-pretty/stdout.golden similarity index 72% rename from cmd/print/tests/simple/env.golden rename to cmd/print/tests/simple-pretty/stdout.golden index d10d7cd..6a7ce24 100644 --- a/cmd/print/tests/simple/env.golden +++ b/cmd/print/tests/simple-pretty/stdout.golden @@ -1,4 +1,4 @@ KEY_A="I'm key A" -# Comment for KEY_B KEY_B="I'm key B" KEY_C="I'm key C" + diff --git a/cmd/print/tests/simple.command.txt b/cmd/print/tests/simple.command.txt index e69de29..6150730 100644 --- a/cmd/print/tests/simple.command.txt +++ b/cmd/print/tests/simple.command.txt @@ -0,0 +1 @@ +--no-color diff --git a/cmd/print/tests/simple-pretty/env.golden b/cmd/print/tests/simple/stdout.golden similarity index 72% rename from cmd/print/tests/simple-pretty/env.golden rename to cmd/print/tests/simple/stdout.golden index 710f007..6a7ce24 100644 --- a/cmd/print/tests/simple-pretty/env.golden +++ b/cmd/print/tests/simple/stdout.golden @@ -1,6 +1,4 @@ KEY_A="I'm key A" - -# Comment for KEY_B KEY_B="I'm key B" - KEY_C="I'm key C" + diff --git a/cmd/print/tests/specific-group.command.txt b/cmd/print/tests/specific-group.command.txt new file mode 100644 index 0000000..de5ce56 --- /dev/null +++ b/cmd/print/tests/specific-group.command.txt @@ -0,0 +1,3 @@ +--no-color +--group +my-first-group diff --git a/cmd/print/tests/full/env.golden b/cmd/print/tests/specific-group.env similarity index 100% rename from cmd/print/tests/full/env.golden rename to cmd/print/tests/specific-group.env diff --git a/cmd/print/tests/specific-group/stdout.golden b/cmd/print/tests/specific-group/stdout.golden new file mode 100644 index 0000000..6a7ce24 --- /dev/null +++ b/cmd/print/tests/specific-group/stdout.golden @@ -0,0 +1,4 @@ +KEY_A="I'm key A" +KEY_B="I'm key B" +KEY_C="I'm key C" +