Skip to content

Commit 2ed42a8

Browse files
committed
cli-plugins/manager: reformat TestValidateCandidate table
Slightly more verbose, but makes it easier to see properties of each test. Signed-off-by: Sebastiaan van Stijn <[email protected]> (cherry picked from commit 057f312) Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 4bac500 commit 2ed42a8

File tree

1 file changed

+72
-22
lines changed

1 file changed

+72
-22
lines changed

cli-plugins/manager/candidate_test.go

Lines changed: 72 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,8 @@ func (c *fakeCandidate) Metadata() ([]byte, error) {
3232
func TestValidateCandidate(t *testing.T) {
3333
const (
3434
goodPluginName = metadata.NamePrefix + "goodplugin"
35-
36-
builtinName = metadata.NamePrefix + "builtin"
37-
builtinAlias = metadata.NamePrefix + "alias"
35+
builtinName = metadata.NamePrefix + "builtin"
36+
builtinAlias = metadata.NamePrefix + "alias"
3837

3938
badPrefixPath = "/usr/local/libexec/cli-plugins/wobble"
4039
badNamePath = "/usr/local/libexec/cli-plugins/docker-123456"
@@ -50,32 +49,83 @@ func TestValidateCandidate(t *testing.T) {
5049
})
5150

5251
for _, tc := range []struct {
53-
name string
54-
c *fakeCandidate
52+
name string
53+
plugin *fakeCandidate
5554

5655
// Either err or invalid may be non-empty, but not both (both can be empty for a good plugin).
5756
err string
5857
invalid string
5958
}{
60-
/* Each failing one of the tests */
61-
{name: "empty path", c: &fakeCandidate{path: ""}, err: "plugin candidate path cannot be empty"},
62-
{name: "bad prefix", c: &fakeCandidate{path: badPrefixPath}, err: fmt.Sprintf("does not have %q prefix", metadata.NamePrefix)},
63-
{name: "bad path", c: &fakeCandidate{path: badNamePath}, invalid: "did not match"},
64-
{name: "builtin command", c: &fakeCandidate{path: builtinName}, invalid: `plugin "builtin" duplicates builtin command`},
65-
{name: "builtin alias", c: &fakeCandidate{path: builtinAlias}, invalid: `plugin "alias" duplicates an alias of builtin command "builtin"`},
66-
{name: "fetch failure", c: &fakeCandidate{path: goodPluginPath, exec: false}, invalid: fmt.Sprintf("failed to fetch metadata: faked a failure to exec %q", goodPluginPath)},
67-
{name: "metadata not json", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `xyzzy`}, invalid: "invalid character"},
68-
{name: "empty schemaversion", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{}`}, invalid: `plugin SchemaVersion "" is not valid`},
69-
{name: "invalid schemaversion", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "xyzzy"}`}, invalid: `plugin SchemaVersion "xyzzy" is not valid`},
70-
{name: "no vendor", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0"}`}, invalid: "plugin metadata does not define a vendor"},
71-
{name: "empty vendor", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0", "Vendor": ""}`}, invalid: "plugin metadata does not define a vendor"},
72-
// This one should work
73-
{name: "valid", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0", "Vendor": "e2e-testing"}`}},
74-
// Including the deprecated "experimental" field should not break processing.
75-
{name: "with legacy experimental", c: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0", "Vendor": "e2e-testing", "Experimental": true}`}},
59+
// Invalid cases.
60+
{
61+
name: "empty path",
62+
plugin: &fakeCandidate{path: ""},
63+
err: "plugin candidate path cannot be empty",
64+
},
65+
{
66+
name: "bad prefix",
67+
plugin: &fakeCandidate{path: badPrefixPath},
68+
err: fmt.Sprintf("does not have %q prefix", metadata.NamePrefix),
69+
},
70+
{
71+
name: "bad path",
72+
plugin: &fakeCandidate{path: badNamePath},
73+
invalid: "did not match",
74+
},
75+
{
76+
name: "builtin command",
77+
plugin: &fakeCandidate{path: builtinName},
78+
invalid: `plugin "builtin" duplicates builtin command`,
79+
},
80+
{
81+
name: "builtin alias",
82+
plugin: &fakeCandidate{path: builtinAlias},
83+
invalid: `plugin "alias" duplicates an alias of builtin command "builtin"`,
84+
},
85+
{
86+
name: "fetch failure",
87+
plugin: &fakeCandidate{path: goodPluginPath, exec: false},
88+
invalid: fmt.Sprintf("failed to fetch metadata: faked a failure to exec %q", goodPluginPath),
89+
},
90+
{
91+
name: "metadata not json",
92+
plugin: &fakeCandidate{path: goodPluginPath, exec: true, meta: `xyzzy`},
93+
invalid: "invalid character",
94+
},
95+
{
96+
name: "empty schemaversion",
97+
plugin: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{}`},
98+
invalid: `plugin SchemaVersion "" is not valid`,
99+
},
100+
{
101+
name: "invalid schemaversion",
102+
plugin: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "xyzzy"}`},
103+
invalid: `plugin SchemaVersion "xyzzy" is not valid`,
104+
},
105+
{
106+
name: "no vendor",
107+
plugin: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0"}`},
108+
invalid: "plugin metadata does not define a vendor",
109+
},
110+
{
111+
name: "empty vendor",
112+
plugin: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0", "Vendor": ""}`},
113+
invalid: "plugin metadata does not define a vendor",
114+
},
115+
116+
// Valid cases.
117+
{
118+
name: "valid",
119+
plugin: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0", "Vendor": "e2e-testing"}`},
120+
},
121+
{
122+
// Including the deprecated "experimental" field should not break processing.
123+
name: "with legacy experimental",
124+
plugin: &fakeCandidate{path: goodPluginPath, exec: true, meta: `{"SchemaVersion": "0.1.0", "Vendor": "e2e-testing", "Experimental": true}`},
125+
},
76126
} {
77127
t.Run(tc.name, func(t *testing.T) {
78-
p, err := newPlugin(tc.c, fakeroot.Commands())
128+
p, err := newPlugin(tc.plugin, fakeroot.Commands())
79129
switch {
80130
case tc.err != "":
81131
assert.ErrorContains(t, err, tc.err)

0 commit comments

Comments
 (0)