github.com/hairyhenderson/gomplate/v4@v4.0.0-pre-2.0.20240520121557-362f058f0c93/internal/tests/integration/datasources_env_test.go (about)

     1  package integration
     2  
     3  import (
     4  	"testing"
     5  )
     6  
     7  func TestDatasources_Env(t *testing.T) {
     8  	o, e, err := cmd(t, "-d", "foo=env:FOO", "-i", `{{ ds "foo" }}`).
     9  		withEnv("HELLO_WORLD", "hello world").
    10  		withEnv("HELLO_UNIVERSE", "hello universe").
    11  		withEnv("FOO", "bar").
    12  		withEnv("foo", "baz").
    13  		run()
    14  	// Windows envvars are case-insensitive
    15  	if isWindows {
    16  		assertSuccess(t, o, e, err, "baz")
    17  	} else {
    18  		assertSuccess(t, o, e, err, "bar")
    19  	}
    20  
    21  	o, e, err = cmd(t,
    22  		"-d", "foo=env:///foo", "-i", `{{ ds "foo" }}`).
    23  		withEnv("HELLO_WORLD", "hello world").
    24  		withEnv("HELLO_UNIVERSE", "hello universe").
    25  		withEnv("FOO", "bar").
    26  		withEnv("foo", "baz").
    27  		run()
    28  	assertSuccess(t, o, e, err, "baz")
    29  
    30  	o, e, err = cmd(t, "-d", "e=env:json_value?type=application/json",
    31  		"-i", `{{ (ds "e").value}}`).
    32  		withEnv("json_value", `{"value":"corge"}`).
    33  		run()
    34  	assertSuccess(t, o, e, err, "corge")
    35  }