Update internal/plugin/metadata_test.go

Check test failure string

Co-authored-by: Jesse Simpson <jesse.simpson36@gmail.com>
Signed-off-by: Scott Rigby <scott@r6by.com>
pull/31145/head
Scott Rigby 1 year ago committed by GitHub
parent 1321b1e315
commit 1238a78300
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -66,19 +66,20 @@ func TestValidatePluginData(t *testing.T) {
} }
for i, item := range []struct { for i, item := range []struct {
pass bool pass bool
plug Plugin plug Plugin
errString string
}{ }{
{true, mockSubprocessCLIPlugin(t, "abcdefghijklmnopqrstuvwxyz0123456789_-ABC")}, {true, mockSubprocessCLIPlugin(t, "abcdefghijklmnopqrstuvwxyz0123456789_-ABC"), ""},
{true, mockSubprocessCLIPlugin(t, "foo-bar-FOO-BAR_1234")}, {true, mockSubprocessCLIPlugin(t, "foo-bar-FOO-BAR_1234"), ""},
{false, mockSubprocessCLIPlugin(t, "foo -bar")}, {false, mockSubprocessCLIPlugin(t, "foo -bar"), "invalid name"},
{false, mockSubprocessCLIPlugin(t, "$foo -bar")}, // Test leading chars {false, mockSubprocessCLIPlugin(t, "$foo -bar"), "invalid name"}, // Test leading chars
{false, mockSubprocessCLIPlugin(t, "foo -bar ")}, // Test trailing chars {false, mockSubprocessCLIPlugin(t, "foo -bar "), "invalid name"}, // Test trailing chars
{false, mockSubprocessCLIPlugin(t, "foo\nbar")}, // Test newline {false, mockSubprocessCLIPlugin(t, "foo\nbar"), "invalid name"}, // Test newline
{true, mockNoCommand}, // Test no command metadata works {true, mockNoCommand, ""}, // Test no command metadata works
{true, mockLegacyCommand}, // Test legacy command metadata works {true, mockLegacyCommand, ""}, // Test legacy command metadata works
{false, mockWithCommand}, // Test platformCommand and command both set fails {false, mockWithCommand, "runtime config validation failed: both platformCommand and command are set"}, // Test platformCommand and command both set fails
{false, mockWithHooks}, // Test platformHooks and hooks both set fails {false, mockWithHooks, "runtime config validation failed: both platformHooks and hooks are set"}, // Test platformHooks and hooks both set fails
} { } {
err := item.plug.Metadata().Validate() err := item.plug.Metadata().Validate()
if item.pass && err != nil { if item.pass && err != nil {
@ -86,6 +87,9 @@ func TestValidatePluginData(t *testing.T) {
} else if !item.pass && err == nil { } else if !item.pass && err == nil {
t.Errorf("expected case %d to fail", i) t.Errorf("expected case %d to fail", i)
} }
if !item.pass && err.Error() != item.errString {
t.Errorf("index [%d]: expected the following error: %s, but got: %s", i, item.errString, err.Error())
}
} }
} }

Loading…
Cancel
Save