github.com/hairyhenderson/gomplate/v4@v4.0.0-pre-2.0.20240520121557-362f058f0c93/internal/tests/integration/test_test.go (about) 1 package integration 2 3 import ( 4 "os" 5 "testing" 6 7 "gotest.tools/v3/assert" 8 ) 9 10 func TestTest_Fail(t *testing.T) { 11 _, _, err := cmd(t, "-i", "{{ fail }}").run() 12 assert.ErrorContains(t, err, `template generation failed`) 13 14 _, _, err = cmd(t, "-i", "{{ fail `some message` }}").run() 15 assert.ErrorContains(t, err, `some message`) 16 } 17 18 func TestTest_Required(t *testing.T) { 19 os.Unsetenv("FOO") 20 _, _, err := cmd(t, "-i", `{{getenv "FOO" | required "FOO missing" }}`).run() 21 assert.ErrorContains(t, err, "FOO missing") 22 23 o, e, err := cmd(t, "-i", `{{getenv "FOO" | required "FOO missing" }}`). 24 withEnv("FOO", "bar").run() 25 assertSuccess(t, o, e, err, "bar") 26 27 _, _, err = cmd(t, "-d", "in=stdin:///?type=application/yaml", 28 "-i", `{{ (ds "in").foo | required "foo should not be null" }}`). 29 withStdin(`foo: null`).run() 30 assert.ErrorContains(t, err, "foo should not be null") 31 32 o, e, err = cmd(t, "-d", "in=stdin:///?type=application/yaml", 33 "-i", `{{ (ds "in").foo | required }}`). 34 withStdin(`foo: []`).run() 35 assertSuccess(t, o, e, err, "[]") 36 37 o, e, err = cmd(t, "-d", "in=stdin:///?type=application/yaml", 38 "-i", `{{ (ds "in").foo | required }}`). 39 withStdin(`foo: {}`).run() 40 assertSuccess(t, o, e, err, "map[]") 41 42 o, e, err = cmd(t, "-d", "in=stdin:///?type=application/yaml", 43 "-i", `{{ (ds "in").foo | required }}`). 44 withStdin(`foo: 0`).run() 45 assertSuccess(t, o, e, err, "0") 46 47 o, e, err = cmd(t, "-d", "in=stdin:///?type=application/yaml", 48 "-i", `{{ (ds "in").foo | required }}`). 49 withStdin(`foo: false`).run() 50 assertSuccess(t, o, e, err, "false") 51 }