MCPcopy
hub / github.com/helm/helm / TestValidatePluginData

Function TestValidatePluginData

internal/plugin/metadata_test.go:25–75  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23)
24
25func TestValidatePluginData(t *testing.T) {
26
27 // A mock plugin with no commands
28 mockNoCommand := mockSubprocessCLIPlugin(t, "foo")
29 mockNoCommand.metadata.RuntimeConfig = &RuntimeConfigSubprocess{
30 PlatformCommand: []PlatformCommand{},
31 PlatformHooks: map[string][]PlatformCommand{},
32 }
33
34 // A mock plugin with legacy commands
35 mockLegacyCommand := mockSubprocessCLIPlugin(t, "foo")
36 mockLegacyCommand.metadata.RuntimeConfig = &RuntimeConfigSubprocess{
37 PlatformCommand: []PlatformCommand{
38 {
39 Command: "echo \"mock plugin\"",
40 },
41 },
42 PlatformHooks: map[string][]PlatformCommand{
43 Install: {
44 PlatformCommand{
45 Command: "echo installing...",
46 },
47 },
48 },
49 }
50
51 for i, item := range []struct {
52 pass bool
53 plug Plugin
54 errString string
55 }{
56 {true, mockSubprocessCLIPlugin(t, "abcdefghijklmnopqrstuvwxyz0123456789_-ABC"), ""},
57 {true, mockSubprocessCLIPlugin(t, "foo-bar-FOO-BAR_1234"), ""},
58 {false, mockSubprocessCLIPlugin(t, "foo -bar"), "invalid plugin name"},
59 {false, mockSubprocessCLIPlugin(t, "$foo -bar"), "invalid plugin name"}, // Test leading chars
60 {false, mockSubprocessCLIPlugin(t, "foo -bar "), "invalid plugin name"}, // Test trailing chars
61 {false, mockSubprocessCLIPlugin(t, "foo\nbar"), "invalid plugin name"}, // Test newline
62 {true, mockNoCommand, ""}, // Test no command metadata works
63 {true, mockLegacyCommand, ""}, // Test legacy command metadata works
64 } {
65 err := item.plug.Metadata().Validate()
66 if item.pass && err != nil {
67 t.Errorf("failed to validate case %d: %s", i, err)
68 } else if !item.pass && err == nil {
69 t.Errorf("expected case %d to fail", i)
70 }
71 if !item.pass && !strings.Contains(err.Error(), item.errString) {
72 t.Errorf("index [%d]: expected error to contain: %s, but got: %s", i, item.errString, err.Error())
73 }
74 }
75}
76
77func TestMetadataValidateVersion(t *testing.T) {
78 testValid := map[string]struct {

Callers

nothing calls this directly

Calls 5

mockSubprocessCLIPluginFunction · 0.85
ContainsMethod · 0.80
ValidateMethod · 0.65
MetadataMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…