mirror of
https://github.com/docker/cli.git
synced 2026-08-28 10:05:17 -05:00
This allows for slighly cleaner / more natural placeholders, as it
doesn't require the context (`.`) to be specified;
- `{{command}}` instead of `{{.Command}}` or `{{command .}}`
- `{{flagValue "my-flag"}}` instead of `{{.FlagValue "my-flag"}} or `{{flagValue . "my-flag"}}`
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
51 lines
867 B
Go
51 lines
867 B
Go
package hooks_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/docker/cli/cli-plugins/hooks"
|
|
)
|
|
|
|
func TestTemplateHelpers(t *testing.T) {
|
|
tests := []struct {
|
|
doc string
|
|
got func() string
|
|
want string
|
|
}{
|
|
{
|
|
doc: "subcommand name",
|
|
got: hooks.TemplateReplaceSubcommandName,
|
|
want: `{{command}}`,
|
|
},
|
|
{
|
|
doc: "flag value",
|
|
got: func() string {
|
|
return hooks.TemplateReplaceFlagValue("name")
|
|
},
|
|
want: `{{flagValue "name"}}`,
|
|
},
|
|
{
|
|
doc: "arg",
|
|
got: func() string {
|
|
return hooks.TemplateReplaceArg(0)
|
|
},
|
|
want: `{{argValue 0}}`,
|
|
},
|
|
{
|
|
doc: "arg",
|
|
got: func() string {
|
|
return hooks.TemplateReplaceArg(3)
|
|
},
|
|
want: `{{argValue 3}}`,
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.doc, func(t *testing.T) {
|
|
if got := tc.got(); got != tc.want {
|
|
t.Fatalf("expected %q, got %q", tc.want, got)
|
|
}
|
|
})
|
|
}
|
|
}
|