summaryrefslogtreecommitdiff
path: root/context_test.go
diff options
context:
space:
mode:
authorDave Henderson <dhenderson@gmail.com>2019-11-11 16:03:16 -0500
committerDave Henderson <dhenderson@gmail.com>2020-05-03 22:12:08 -0400
commit7ff174a86a935191a684f0c63f9e2a48058fabfb (patch)
tree00f59ab63d0e581d821307df57abd5cb6f2986c0 /context_test.go
parent8c8287777495dbb1e2b24e570db0bd504bf18372 (diff)
Support a config file to use instead of commandline arguments
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'context_test.go')
-rw-r--r--context_test.go26
1 files changed, 8 insertions, 18 deletions
diff --git a/context_test.go b/context_test.go
index ab273749..94f2b51b 100644
--- a/context_test.go
+++ b/context_test.go
@@ -1,11 +1,13 @@
package gomplate
import (
+ "context"
"net/url"
"os"
"testing"
"github.com/hairyhenderson/gomplate/v3/data"
+ "github.com/hairyhenderson/gomplate/v3/internal/config"
"github.com/stretchr/testify/assert"
)
@@ -24,7 +26,8 @@ func TestEnvGetsUpdatedEnvironment(t *testing.T) {
}
func TestCreateContext(t *testing.T) {
- c, err := createTmplContext(nil, nil)
+ ctx := context.TODO()
+ c, err := createTmplContext(ctx, nil, nil)
assert.NoError(t, err)
assert.Empty(t, c)
@@ -40,31 +43,18 @@ func TestCreateContext(t *testing.T) {
}
os.Setenv("foo", "foo: bar")
defer os.Unsetenv("foo")
- c, err = createTmplContext([]string{"foo=" + fooURL}, d)
+ c, err = createTmplContext(ctx, map[string]config.DSConfig{"foo": {URL: uf}}, d)
assert.NoError(t, err)
assert.IsType(t, &tmplctx{}, c)
- ctx := c.(*tmplctx)
- ds := ((*ctx)["foo"]).(map[string]interface{})
+ tctx := c.(*tmplctx)
+ ds := ((*tctx)["foo"]).(map[string]interface{})
assert.Equal(t, "bar", ds["foo"])
os.Setenv("bar", "bar: baz")
defer os.Unsetenv("bar")
- c, err = createTmplContext([]string{".=" + barURL}, d)
+ c, err = createTmplContext(ctx, map[string]config.DSConfig{".": {URL: ub}}, d)
assert.NoError(t, err)
assert.IsType(t, map[string]interface{}{}, c)
ds = c.(map[string]interface{})
assert.Equal(t, "baz", ds["bar"])
}
-
-func TestParseAlias(t *testing.T) {
- testdata := map[string]string{
- "": "",
- "foo": "foo",
- "foo.bar": "foo",
- "a=b": "a",
- ".=foo": ".",
- }
- for k, v := range testdata {
- assert.Equal(t, v, parseAlias(k))
- }
-}