Skip to content

Commit e39aa2d

Browse files
author
Tibor Vass
committed
cli-plugins: add test names for easier debugging
Signed-off-by: Tibor Vass <tibor@docker.com>
1 parent 200fada commit e39aa2d

File tree

1 file changed

+35
-30
lines changed

1 file changed

+35
-30
lines changed

cli-plugins/manager/candidate_test.go

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type fakeCandidate struct {
1919
}
2020

2121
func (c *fakeCandidate) Experimental() bool {
22-
return c.allowExperimental
22+
return strings.Contains(c.path, "-experimental/")
2323
}
2424

2525
func (c *fakeCandidate) Path() string {
@@ -40,6 +40,8 @@ func TestValidateCandidate(t *testing.T) {
4040
builtinName = NamePrefix + "builtin"
4141
builtinAlias = NamePrefix + "alias"
4242

43+
goodMeta = `{"SchemaVersion": "0.1.0", "Vendor": "e2e-testing"}`
44+
4345
badPrefixPath = "/usr/local/libexec/cli-plugins/wobble"
4446
badNamePath = "/usr/local/libexec/cli-plugins/docker-123456"
4547
goodPluginPath = "/usr/local/libexec/cli-plugins/" + goodPluginName
@@ -55,43 +57,46 @@ func TestValidateCandidate(t *testing.T) {
5557
})
5658

5759
for _, tc := range []struct {
58-
c *fakeCandidate
60+
name string
61+
c *fakeCandidate
5962

6063
// Either err or invalid may be non-empty, but not both (both can be empty for a good plugin).
6164
err string
6265
invalid string
6366
}{
6467
/* Each failing one of the tests */
65-
{c: &fakeCandidate{path: ""}, err: "plugin candidate path cannot be empty"},
66-
{c: &fakeCandidate{path: badPrefixPath}, err: fmt.Sprintf("does not have %q prefix", NamePrefix)},
67-
{c: &fakeCandidate{path: badNamePath}, invalid: "did not match"},
68-
{c: &fakeCandidate{path: builtinName}, invalid: `plugin "builtin" duplicates builtin command`},
69-
{c: &fakeCandidate{path: builtinAlias}, invalid: `plugin "alias" duplicates an alias of builtin command "builtin"`},
70-
{c: &fakeCandidate{path: goodPluginPath, exec: false}, invalid: fmt.Sprintf("failed to fetch metadata: faked a failure to exec %q", goodPluginPath)},
71-
{c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `xyzzy`}, invalid: "invalid character"},
72-
{c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{}`}, invalid: `plugin SchemaVersion "" is not valid`},
73-
{c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "xyzzy"}`}, invalid: `plugin SchemaVersion "xyzzy" is not valid`},
74-
{c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0"}`}, invalid: "plugin metadata does not define a vendor"},
75-
{c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0", "Vendor": ""}`}, invalid: "plugin metadata does not define a vendor"},
76-
{c: &fakeCandidate{path: experimentalPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0", "Vendor": "e2e-testing"}`}, invalid: "requires experimental CLI"},
68+
{name: "empty path", c: &fakeCandidate{path: ""}, err: "plugin candidate path cannot be empty"},
69+
{name: "bad prefix", c: &fakeCandidate{path: badPrefixPath}, err: fmt.Sprintf("does not have %q prefix", NamePrefix)},
70+
{name: "bad path", c: &fakeCandidate{path: badNamePath}, invalid: "did not match"},
71+
{name: "builtin command", c: &fakeCandidate{path: builtinName}, invalid: `plugin "builtin" duplicates builtin command`},
72+
{name: "builtin alias", c: &fakeCandidate{path: builtinAlias}, invalid: `plugin "alias" duplicates an alias of builtin command "builtin"`},
73+
{name: "fetch failure", c: &fakeCandidate{path: goodPluginPath, exec: false}, invalid: fmt.Sprintf("failed to fetch metadata: faked a failure to exec %q", goodPluginPath)},
74+
{name: "metadata not json", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `xyzzy`}, invalid: "invalid character"},
75+
{name: "empty schemaversion", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{}`}, invalid: `plugin SchemaVersion "" is not valid`},
76+
{name: "invalid schemaversion", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "xyzzy"}`}, invalid: `plugin SchemaVersion "xyzzy" is not valid`},
77+
{name: "no vendor", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0"}`}, invalid: "plugin metadata does not define a vendor"},
78+
{name: "empty vendor", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0", "Vendor": ""}`}, invalid: "plugin metadata does not define a vendor"},
79+
{name: "experimental required", c: &fakeCandidate{path: experimentalPluginPath, exec: true, meta: goodMeta}, invalid: "requires experimental CLI"},
7780
// This one should work
78-
{c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0", "Vendor": "e2e-testing"}`}},
79-
{c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0", "Vendor": "e2e-testing"}`, allowExperimental: true}},
80-
{c: &fakeCandidate{path: experimentalPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0", "Vendor": "e2e-testing"}`, allowExperimental: true}},
81+
{name: "valid", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: goodMeta}},
82+
{name: "valid on experimental CLI", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: goodMeta, allowExperimental: true}},
83+
{name: "experimental on experimental CLI", c: &fakeCandidate{path: experimentalPluginPath, exec: true, meta: goodMeta, allowExperimental: true}},
8184
} {
82-
p, err := newPlugin(tc.c, fakeroot, tc.c.allowExperimental)
83-
if tc.err != "" {
84-
assert.ErrorContains(t, err, tc.err)
85-
} else if tc.invalid != "" {
86-
assert.NilError(t, err)
87-
assert.Assert(t, cmp.ErrorType(p.Err, reflect.TypeOf(&pluginError{})))
88-
assert.ErrorContains(t, p.Err, tc.invalid)
89-
} else {
90-
assert.NilError(t, err)
91-
assert.Equal(t, NamePrefix+p.Name, goodPluginName)
92-
assert.Equal(t, p.SchemaVersion, "0.1.0")
93-
assert.Equal(t, p.Vendor, "e2e-testing")
94-
}
85+
t.Run(tc.name, func(t *testing.T) {
86+
p, err := newPlugin(tc.c, fakeroot, tc.c.allowExperimental)
87+
if tc.err != "" {
88+
assert.ErrorContains(t, err, tc.err)
89+
} else if tc.invalid != "" {
90+
assert.NilError(t, err)
91+
assert.Assert(t, cmp.ErrorType(p.Err, reflect.TypeOf(&pluginError{})))
92+
assert.ErrorContains(t, p.Err, tc.invalid)
93+
} else {
94+
assert.NilError(t, err)
95+
assert.Equal(t, NamePrefix+p.Name, goodPluginName)
96+
assert.Equal(t, p.SchemaVersion, "0.1.0")
97+
assert.Equal(t, p.Vendor, "e2e-testing")
98+
}
99+
})
95100
}
96101
}
97102

0 commit comments

Comments
 (0)