Skip to content

Commit bb8e89b

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

File tree

1 file changed

+36
-32
lines changed

1 file changed

+36
-32
lines changed

cli-plugins/manager/candidate_test.go

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ func TestValidateCandidate(t *testing.T) {
3636
builtinName = NamePrefix + "builtin"
3737
builtinAlias = NamePrefix + "alias"
3838

39-
badPrefixPath = "/usr/local/libexec/cli-plugins/wobble"
40-
badNamePath = "/usr/local/libexec/cli-plugins/docker-123456"
41-
goodPluginPath = "/usr/local/libexec/cli-plugins/" + goodPluginName
39+
badPrefixPath = "/usr/local/libexec/cli-plugins/wobble"
40+
badNamePath = "/usr/local/libexec/cli-plugins/docker-123456"
41+
goodPluginPath = "/usr/local/libexec/cli-plugins/" + goodPluginName
42+
metaExperimental = `{"SchemaVersion": "0.1.0", "Vendor": "e2e-testing", "Experimental": true}`
4243
)
4344

4445
fakeroot := &cobra.Command{Use: "docker"}
@@ -50,43 +51,46 @@ func TestValidateCandidate(t *testing.T) {
5051
})
5152

5253
for _, tc := range []struct {
53-
c *fakeCandidate
54+
name string
55+
c *fakeCandidate
5456

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

0 commit comments

Comments
 (0)