diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2024-05-29 20:36:24 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-05-29 20:36:24 -0400 |
| commit | 95a06b9fc94c44af51588379c4e443e986b7e4d5 (patch) | |
| tree | c17f08a12c020ef45302800d778d02ee18bfcc24 /context_test.go | |
| parent | 362f058f0c93900c7bd7462aac200597e70ebfb7 (diff) | |
chore!: Replacing the data.Data type with a datasource registry (#2083)
* chore!: Replacing the data.Data type with a datasource registry
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
* chore(lint): fix lint warning
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
---------
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'context_test.go')
| -rw-r--r-- | context_test.go | 21 |
1 files changed, 10 insertions, 11 deletions
diff --git a/context_test.go b/context_test.go index a92818d2..903a0fc7 100644 --- a/context_test.go +++ b/context_test.go @@ -7,7 +7,6 @@ import ( "testing" "github.com/hairyhenderson/go-fsimpl" - "github.com/hairyhenderson/gomplate/v4/data" "github.com/hairyhenderson/gomplate/v4/internal/config" "github.com/hairyhenderson/gomplate/v4/internal/datafs" @@ -30,7 +29,10 @@ func TestEnvGetsUpdatedEnvironment(t *testing.T) { func TestCreateContext(t *testing.T) { ctx := context.Background() - c, err := createTmplContext(ctx, nil, nil) + reg := datafs.NewRegistry() + sr := datafs.NewSourceReader(reg) + + c, err := createTmplContext(ctx, nil, sr) require.NoError(t, err) assert.Empty(t, c) @@ -43,15 +45,12 @@ func TestCreateContext(t *testing.T) { barURL := "env:///bar?type=application/yaml" uf, _ := url.Parse(fooURL) ub, _ := url.Parse(barURL) - //nolint:staticcheck - d := &data.Data{ - Sources: map[string]config.DataSource{ - "foo": {URL: uf}, - ".": {URL: ub}, - }, - } + + reg.Register("foo", config.DataSource{URL: uf}) + reg.Register(".", config.DataSource{URL: ub}) + t.Setenv("foo", "foo: bar") - c, err = createTmplContext(ctx, []string{"foo"}, d) + c, err = createTmplContext(ctx, []string{"foo"}, sr) require.NoError(t, err) assert.IsType(t, &tmplctx{}, c) tctx := c.(*tmplctx) @@ -59,7 +58,7 @@ func TestCreateContext(t *testing.T) { assert.Equal(t, "bar", ds["foo"]) t.Setenv("bar", "bar: baz") - c, err = createTmplContext(ctx, []string{"."}, d) + c, err = createTmplContext(ctx, []string{"."}, sr) require.NoError(t, err) assert.IsType(t, map[string]interface{}{}, c) ds = c.(map[string]interface{}) |
