Skip to content

Commit

Permalink
Use go-fsimpl to read from datasources
Browse files Browse the repository at this point in the history
Signed-off-by: Dave Henderson <[email protected]>
  • Loading branch information
hairyhenderson committed Dec 5, 2023
1 parent 3a1ee03 commit 41efbd2
Show file tree
Hide file tree
Showing 52 changed files with 1,898 additions and 2,868 deletions.
13 changes: 10 additions & 3 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@ func (c *tmplctx) Env() map[string]string {
}

// createTmplContext reads the datasources for the given aliases
//
//nolint:staticcheck
func createTmplContext(_ context.Context, aliases []string, d *data.Data) (interface{}, error) {
func createTmplContext(ctx context.Context, aliases []string,
//nolint:staticcheck
d *data.Data) (interface{}, error) {

Check failure on line 27 in context.go

View workflow job for this annotation

GitHub Actions / lint

File is not `gofumpt`-ed (gofumpt)
// we need to inject the current context into the Data value, because
// the Datasource method may need it
// TODO: remove this before v4
if d != nil {
d.Ctx = ctx
}

var err error
tctx := &tmplctx{}
for _, a := range aliases {
Expand Down
7 changes: 7 additions & 0 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ import (
"os"
"testing"

"github.com/hairyhenderson/go-fsimpl"
"github.com/hairyhenderson/gomplate/v4/data"
"github.com/hairyhenderson/gomplate/v4/internal/datafs"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
Expand All @@ -31,6 +33,11 @@ func TestCreateContext(t *testing.T) {
require.NoError(t, err)
assert.Empty(t, c)

fsmux := fsimpl.NewMux()
fsmux.Add(datafs.EnvFS)

ctx = datafs.ContextWithFSProvider(ctx, fsmux)

fooURL := "env:///foo?type=application/yaml"
barURL := "env:///bar?type=application/yaml"
uf, _ := url.Parse(fooURL)
Expand Down
Loading

0 comments on commit 41efbd2

Please sign in to comment.