@@ -50,42 +50,43 @@ func TestValidateCandidate(t *testing.T) {
5050 })
5151
5252 for _ , tc := range []struct {
53- c * fakeCandidate
53+ name string
54+ c * fakeCandidate
5455
5556 // Either err or invalid may be non-empty, but not both (both can be empty for a good plugin).
5657 err string
5758 invalid string
5859 }{
5960 /* 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 enabled" },
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" , 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+ {name : "experimental required" , c : & fakeCandidate {path : goodPluginPath , exec : true , meta : `{"SchemaVersion": "0.1.0", "Vendor": "e2e-testing", "Experimental": true}` }, invalid : "requires experimental enabled" },
7273 // 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 }},
74+ {name : "valid" , c : & fakeCandidate {path : goodPluginPath , exec : true , meta : `{"SchemaVersion": "0.1.0", "Vendor": "e2e-testing"}` }},
75+ {name : "valid + allowing experimental" , c : & fakeCandidate {path : goodPluginPath , exec : true , meta : `{"SchemaVersion": "0.1.0", "Vendor": "e2e-testing"}` , allowExperimental : true }},
76+ {name : "experimental + allowing experimental" , c : & fakeCandidate {path : goodPluginPath , exec : true , meta : `{"SchemaVersion": "0.1.0", "Vendor": "e2e-testing", "Experimental": true}` , allowExperimental : true }},
7677 } {
7778 p , err := newPlugin (tc .c , fakeroot , tc .c .allowExperimental )
7879 if tc .err != "" {
79- assert .ErrorContains (t , err , tc .err )
80+ assert .ErrorContains (t , err , tc .err , tc . name )
8081 } 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 )
82+ assert .NilError (t , err , tc . name )
83+ assert .Assert (t , cmp .ErrorType (p .Err , reflect .TypeOf (& pluginError {})), tc . name )
84+ assert .ErrorContains (t , p .Err , tc .invalid , tc . name )
8485 } 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" )
86+ assert .NilError (t , err , tc . name )
87+ assert .Equal (t , NamePrefix + p .Name , goodPluginName , tc . name )
88+ assert .Equal (t , p .SchemaVersion , "0.1.0" , tc . name )
89+ assert .Equal (t , p .Vendor , "e2e-testing" , tc . name )
8990 }
9091 }
9192}
0 commit comments