diff options
| author | Dave Henderson <dhenderson@gmail.com> | 2019-11-11 16:03:16 -0500 |
|---|---|---|
| committer | Dave Henderson <dhenderson@gmail.com> | 2020-05-03 22:12:08 -0400 |
| commit | 7ff174a86a935191a684f0c63f9e2a48058fabfb (patch) | |
| tree | 00f59ab63d0e581d821307df57abd5cb6f2986c0 /plugins_test.go | |
| parent | 8c8287777495dbb1e2b24e570db0bd504bf18372 (diff) | |
Support a config file to use instead of commandline arguments
Signed-off-by: Dave Henderson <dhenderson@gmail.com>
Diffstat (limited to 'plugins_test.go')
| -rw-r--r-- | plugins_test.go | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/plugins_test.go b/plugins_test.go index 07e23259..d1292eaa 100644 --- a/plugins_test.go +++ b/plugins_test.go @@ -7,54 +7,48 @@ import ( "gotest.tools/v3/assert" "gotest.tools/v3/assert/cmp" -) - -func TestNewPlugin(t *testing.T) { - ctx := context.TODO() - in := "foo" - _, err := newPlugin(ctx, in) - assert.ErrorContains(t, err, "") - in = "foo=/bin/bar" - out, err := newPlugin(ctx, in) - assert.NilError(t, err) - assert.Equal(t, "foo", out.name) - assert.Equal(t, "/bin/bar", out.path) -} + "github.com/hairyhenderson/gomplate/v3/internal/config" +) func TestBindPlugins(t *testing.T) { ctx := context.TODO() fm := template.FuncMap{} - in := []string{} - err := bindPlugins(ctx, in, fm) + cfg := &config.Config{ + Plugins: map[string]string{}, + } + err := bindPlugins(ctx, cfg, fm) assert.NilError(t, err) assert.DeepEqual(t, template.FuncMap{}, fm) - in = []string{"foo=bar"} - err = bindPlugins(ctx, in, fm) + cfg.Plugins = map[string]string{"foo": "bar"} + err = bindPlugins(ctx, cfg, fm) assert.NilError(t, err) assert.Check(t, cmp.Contains(fm, "foo")) - err = bindPlugins(ctx, in, fm) + err = bindPlugins(ctx, cfg, fm) assert.ErrorContains(t, err, "already bound") } func TestBuildCommand(t *testing.T) { ctx := context.TODO() data := []struct { - plugin string - args []string - expected []string + name, path string + args []string + expected []string }{ - {"foo=foo", nil, []string{"foo"}}, - {"foo=foo", []string{"bar"}, []string{"foo", "bar"}}, - {"foo=foo.bat", nil, []string{"cmd.exe", "/c", "foo.bat"}}, - {"foo=foo.cmd", []string{"bar"}, []string{"cmd.exe", "/c", "foo.cmd", "bar"}}, - {"foo=foo.ps1", []string{"bar", "baz"}, []string{"pwsh", "-File", "foo.ps1", "bar", "baz"}}, + {"foo", "foo", nil, []string{"foo"}}, + {"foo", "foo", []string{"bar"}, []string{"foo", "bar"}}, + {"foo", "foo.bat", nil, []string{"cmd.exe", "/c", "foo.bat"}}, + {"foo", "foo.cmd", []string{"bar"}, []string{"cmd.exe", "/c", "foo.cmd", "bar"}}, + {"foo", "foo.ps1", []string{"bar", "baz"}, []string{"pwsh", "-File", "foo.ps1", "bar", "baz"}}, } for _, d := range data { - p, err := newPlugin(ctx, d.plugin) - assert.NilError(t, err) + p := &plugin{ + ctx: ctx, + name: d.name, + path: d.path, + } name, args := p.buildCommand(d.args) actual := append([]string{name}, args...) assert.DeepEqual(t, d.expected, actual) |
