summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2024-05-11 15:20:45 -0400
committerGitHub <noreply@github.com>2024-05-11 19:20:45 +0000
commit916ebe6ea6d0319a37f0c4b62fd5e4a189f3dc50 (patch)
tree89422b20e758e8ccf5c35cf6cd1f36f759532362 /internal
parenta55441b886ee692f8734e6c561ae0ebebff64a55 (diff)
feat!: Always suppress empty output (#1981)
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'internal')
-rw-r--r--internal/cmd/config.go4
-rw-r--r--internal/cmd/config_test.go15
-rw-r--r--internal/config/configfile.go5
-rw-r--r--internal/iohelpers/writers.go10
-rw-r--r--internal/tests/integration/basic_test.go3
-rw-r--r--internal/tests/integration/gomplateignore_test.go136
6 files changed, 78 insertions, 95 deletions
diff --git a/internal/cmd/config.go b/internal/cmd/config.go
index 62777061..fc64f8e4 100644
--- a/internal/cmd/config.go
+++ b/internal/cmd/config.go
@@ -250,10 +250,6 @@ func applyEnvVars(_ context.Context, cfg *config.Config) (*config.Config, error)
cfg.PluginTimeout = t
}
- if !cfg.SuppressEmpty && conv.ToBool(env.Getenv("GOMPLATE_SUPPRESS_EMPTY", "false")) {
- cfg.SuppressEmpty = true
- }
-
if !cfg.Experimental && conv.ToBool(env.Getenv("GOMPLATE_EXPERIMENTAL", "false")) {
cfg.Experimental = true
}
diff --git a/internal/cmd/config_test.go b/internal/cmd/config_test.go
index a3ff4935..1c9adfe5 100644
--- a/internal/cmd/config_test.go
+++ b/internal/cmd/config_test.go
@@ -221,21 +221,6 @@ func TestApplyEnvVars(t *testing.T) {
},
{
&config.Config{},
- &config.Config{SuppressEmpty: false},
- "GOMPLATE_SUPPRESS_EMPTY", "bogus",
- },
- {
- &config.Config{},
- &config.Config{SuppressEmpty: true},
- "GOMPLATE_SUPPRESS_EMPTY", "true",
- },
- {
- &config.Config{SuppressEmpty: true},
- &config.Config{SuppressEmpty: true},
- "GOMPLATE_SUPPRESS_EMPTY", "false",
- },
- {
- &config.Config{},
&config.Config{Experimental: false},
"GOMPLATE_EXPERIMENTAL", "bogus",
},
diff --git a/internal/config/configfile.go b/internal/config/configfile.go
index 76fc5306..d255a36c 100644
--- a/internal/config/configfile.go
+++ b/internal/config/configfile.go
@@ -69,9 +69,8 @@ type Config struct {
PluginTimeout time.Duration `yaml:"pluginTimeout,omitempty"`
- ExecPipe bool `yaml:"execPipe,omitempty"`
- SuppressEmpty bool `yaml:"suppressEmpty,omitempty"`
- Experimental bool `yaml:"experimental,omitempty"`
+ ExecPipe bool `yaml:"execPipe,omitempty"`
+ Experimental bool `yaml:"experimental,omitempty"`
}
type experimentalCtxKey struct{}
diff --git a/internal/iohelpers/writers.go b/internal/iohelpers/writers.go
index 870fa4cb..543c050b 100644
--- a/internal/iohelpers/writers.go
+++ b/internal/iohelpers/writers.go
@@ -82,17 +82,21 @@ func allWhitespace(p []byte) bool {
// NopCloser returns a WriteCloser with a no-op Close method wrapping
// the provided io.Writer.
-type NopCloser struct {
+func NopCloser(w io.Writer) io.WriteCloser {
+ return &nopCloser{Writer: w}
+}
+
+type nopCloser struct {
io.Writer
}
// Close - implements io.Closer
-func (n *NopCloser) Close() error {
+func (n *nopCloser) Close() error {
return nil
}
var (
- _ io.WriteCloser = (*NopCloser)(nil)
+ _ io.WriteCloser = (*nopCloser)(nil)
_ io.WriteCloser = (*emptySkipper)(nil)
_ io.WriteCloser = (*sameSkipper)(nil)
)
diff --git a/internal/tests/integration/basic_test.go b/internal/tests/integration/basic_test.go
index 1e61646f..d2c4fa35 100644
--- a/internal/tests/integration/basic_test.go
+++ b/internal/tests/integration/basic_test.go
@@ -178,8 +178,7 @@ func TestBasic_EmptyOutputSuppression(t *testing.T) {
tmpDir := setupBasicTest(t)
out := tmpDir.Join("out")
o, e, err := cmd(t, "-i", `{{print "\t \n\n\r\n\t\t \v\n"}}`,
- "-o", out).
- withEnv("GOMPLATE_SUPPRESS_EMPTY", "true").run()
+ "-o", out).run()
assertSuccess(t, o, e, err, "")
_, err = os.Stat(out)
diff --git a/internal/tests/integration/gomplateignore_test.go b/internal/tests/integration/gomplateignore_test.go
index a49d41ed..6679a8b4 100644
--- a/internal/tests/integration/gomplateignore_test.go
+++ b/internal/tests/integration/gomplateignore_test.go
@@ -70,8 +70,8 @@ func TestGomplateignore_Simple(t *testing.T) {
files, err := execute(t, `# all dot files
.*
*.log`,
- tfs.WithFile("empty.log", ""),
- tfs.WithFile("rain.txt", ""))
+ tfs.WithFile("foo.log", "..."),
+ tfs.WithFile("rain.txt", "..."))
require.NoError(t, err)
assert.Equal(t, []string{"rain.txt"}, files)
@@ -91,12 +91,12 @@ f[o]o/bar
tfs.WithDir("foo",
tfs.WithDir("bar",
tfs.WithDir("tool",
- tfs.WithFile("lex.txt", ""),
+ tfs.WithFile("lex.txt", "..."),
),
- tfs.WithFile("1.txt", ""),
+ tfs.WithFile("1.txt", "..."),
),
tfs.WithDir("tar",
- tfs.WithFile("2.txt", ""),
+ tfs.WithFile("2.txt", "..."),
),
),
)
@@ -110,10 +110,10 @@ func TestGomplateignore_Root(t *testing.T) {
files, err := execute(t, `.gomplateignore
/1.txt`,
tfs.WithDir("sub",
- tfs.WithFile("1.txt", ""),
- tfs.WithFile("2.txt", ""),
+ tfs.WithFile("1.txt", "..."),
+ tfs.WithFile("2.txt", "..."),
),
- tfs.WithFile("1.txt", ""),
+ tfs.WithFile("1.txt", "..."),
)
require.NoError(t, err)
@@ -127,14 +127,14 @@ func TestGomplateignore_Exclusion(t *testing.T) {
!/e2.txt
en/e3.txt
!`,
- tfs.WithFile("!", ""),
- tfs.WithFile("e1.txt", ""),
- tfs.WithFile("e2.txt", ""),
- tfs.WithFile("e3.txt", ""),
+ tfs.WithFile("!", "xxx"),
+ tfs.WithFile("e1.txt", "xxx"),
+ tfs.WithFile("e2.txt", "xxx"),
+ tfs.WithFile("e3.txt", "xxx"),
tfs.WithDir("en",
- tfs.WithFile("e1.txt", ""),
- tfs.WithFile("e2.txt", ""),
- tfs.WithFile("e3.txt", ""),
+ tfs.WithFile("e1.txt", "xxx"),
+ tfs.WithFile("e2.txt", "xxx"),
+ tfs.WithFile("e3.txt", "xxx"),
),
)
@@ -148,13 +148,13 @@ func TestGomplateignore_Nested(t *testing.T) {
tfs.WithDir("inner",
tfs.WithDir("inner2",
tfs.WithFile(".gomplateignore", "moss.ini\n!/jess.ini"),
- tfs.WithFile("jess.ini", ""),
- tfs.WithFile("moss.ini", "")),
+ tfs.WithFile("jess.ini", "xxx"),
+ tfs.WithFile("moss.ini", "xxx")),
tfs.WithFile(".gomplateignore", "*.lst\njess.ini"),
- tfs.WithFile("2.lst", ""),
- tfs.WithFile("foo.md", ""),
+ tfs.WithFile("2.lst", "xxx"),
+ tfs.WithFile("foo.md", "xxx"),
),
- tfs.WithFile("1.txt", ""),
+ tfs.WithFile("1.txt", "xxx"),
)
require.NoError(t, err)
@@ -170,17 +170,17 @@ world.txt`,
tfs.WithDir("aa",
tfs.WithDir("a1",
tfs.WithDir("a2",
- tfs.WithFile("hello.txt", ""),
- tfs.WithFile("world.txt", "")),
- tfs.WithFile("hello.txt", ""),
- tfs.WithFile("world.txt", "")),
- tfs.WithFile("hello.txt", ""),
- tfs.WithFile("world.txt", "")),
+ tfs.WithFile("hello.txt", "..."),
+ tfs.WithFile("world.txt", "...")),
+ tfs.WithFile("hello.txt", "..."),
+ tfs.WithFile("world.txt", "...")),
+ tfs.WithFile("hello.txt", "..."),
+ tfs.WithFile("world.txt", "...")),
tfs.WithDir("bb",
- tfs.WithFile("hello.txt", ""),
- tfs.WithFile("world.txt", "")),
- tfs.WithFile("hello.txt", ""),
- tfs.WithFile("world.txt", ""),
+ tfs.WithFile("hello.txt", "..."),
+ tfs.WithFile("world.txt", "...")),
+ tfs.WithFile("hello.txt", "..."),
+ tfs.WithFile("world.txt", "..."),
)
require.NoError(t, err)
@@ -195,11 +195,11 @@ loss.txt
!2.log
`,
tfs.WithDir("loss.txt",
- tfs.WithFile("1.log", ""),
- tfs.WithFile("2.log", "")),
+ tfs.WithFile("1.log", "xxx"),
+ tfs.WithFile("2.log", "xxx")),
tfs.WithDir("foo",
- tfs.WithFile("loss.txt", ""),
- tfs.WithFile("bare.txt", "")),
+ tfs.WithFile("loss.txt", "xxx"),
+ tfs.WithFile("bare.txt", "xxx")),
)
require.NoError(t, err)
@@ -215,11 +215,11 @@ func TestGomplateignore_LeadingSpace(t *testing.T) {
! dart.log
`,
tfs.WithDir("inner",
- tfs.WithFile(" what.txt", ""),
- tfs.WithFile(" dart.log", "")),
+ tfs.WithFile(" what.txt", "xxx"),
+ tfs.WithFile(" dart.log", "xxx")),
tfs.WithDir("inner2",
- tfs.WithFile(" what.txt", "")),
- tfs.WithFile(" what.txt", ""),
+ tfs.WithFile(" what.txt", "xxx")),
+ tfs.WithFile(" what.txt", "xxx"),
)
require.NoError(t, err)
@@ -236,19 +236,19 @@ func TestGomplateignore_WithExcludes(t *testing.T) {
"--exclude", "sprites/*.ini",
},
tfs.WithDir("logs",
- tfs.WithFile("archive.zip", ""),
- tfs.WithFile("engine.log", ""),
- tfs.WithFile("skills.log", "")),
+ tfs.WithFile("archive.zip", "x"),
+ tfs.WithFile("engine.log", "x"),
+ tfs.WithFile("skills.log", "x")),
tfs.WithDir("rules",
- tfs.WithFile("index.csv", ""),
- tfs.WithFile("fire.txt", ""),
- tfs.WithFile("earth.txt", "")),
+ tfs.WithFile("index.csv", "x"),
+ tfs.WithFile("fire.txt", "x"),
+ tfs.WithFile("earth.txt", "x")),
tfs.WithDir("sprites",
- tfs.WithFile("human.csv", ""),
- tfs.WithFile("demon.xml", ""),
- tfs.WithFile("alien.ini", "")),
- tfs.WithFile("manifest.json", ""),
- tfs.WithFile("crash.bin", ""),
+ tfs.WithFile("human.csv", "x"),
+ tfs.WithFile("demon.xml", "x"),
+ tfs.WithFile("alien.ini", "x")),
+ tfs.WithFile("manifest.json", "x"),
+ tfs.WithFile("crash.bin", "x"),
)
require.NoError(t, err)
@@ -265,15 +265,15 @@ func TestGomplateignore_WithIncludes(t *testing.T) {
"--exclude", "rules/*.txt",
},
tfs.WithDir("logs",
- tfs.WithFile("archive.zip", ""),
- tfs.WithFile("engine.log", ""),
- tfs.WithFile("skills.log", "")),
+ tfs.WithFile("archive.zip", "x"),
+ tfs.WithFile("engine.log", "x"),
+ tfs.WithFile("skills.log", "x")),
tfs.WithDir("rules",
- tfs.WithFile("index.csv", ""),
- tfs.WithFile("fire.txt", ""),
- tfs.WithFile("earth.txt", "")),
- tfs.WithFile("manifest.json", ""),
- tfs.WithFile("crash.bin", ""),
+ tfs.WithFile("index.csv", "x"),
+ tfs.WithFile("fire.txt", "x"),
+ tfs.WithFile("earth.txt", "x")),
+ tfs.WithFile("manifest.json", "x"),
+ tfs.WithFile("crash.bin", "x"),
)
require.NoError(t, err)
@@ -290,19 +290,19 @@ func TestGomplateignore_WithExcludeProcessing(t *testing.T) {
"--exclude", "sprites/*.ini",
},
tfs.WithDir("logs",
- tfs.WithFile("archive.zip", ""),
- tfs.WithFile("engine.log", ""),
- tfs.WithFile("skills.log", "")),
+ tfs.WithFile("archive.zip", "xxx"),
+ tfs.WithFile("engine.log", "xxx"),
+ tfs.WithFile("skills.log", "xxx")),
tfs.WithDir("rules",
- tfs.WithFile("index.csv", ""),
- tfs.WithFile("fire.txt", ""),
- tfs.WithFile("earth.txt", "")),
+ tfs.WithFile("index.csv", "xxx"),
+ tfs.WithFile("fire.txt", "xxx"),
+ tfs.WithFile("earth.txt", "xxx")),
tfs.WithDir("sprites",
- tfs.WithFile("human.csv", ""),
- tfs.WithFile("demon.xml", ""),
- tfs.WithFile("alien.ini", "")),
- tfs.WithFile("manifest.json", ""),
- tfs.WithFile("crash.bin", ""),
+ tfs.WithFile("human.csv", "xxx"),
+ tfs.WithFile("demon.xml", "xxx"),
+ tfs.WithFile("alien.ini", "xxx")),
+ tfs.WithFile("manifest.json", "xxx"),
+ tfs.WithFile("crash.bin", "xxx"),
)
require.NoError(t, err)