(t *testing.T)
| 99 | } |
| 100 | |
| 101 | func TestValidatePluginName(t *testing.T) { |
| 102 | tests := []struct { |
| 103 | name string |
| 104 | setup func(dir string) error |
| 105 | pluginRoot string |
| 106 | expectedName string |
| 107 | expectError bool |
| 108 | }{ |
| 109 | { |
| 110 | name: "matching directory and plugin name", |
| 111 | setup: func(dir string) error { |
| 112 | subdir := filepath.Join(dir, "my-plugin") |
| 113 | if err := os.MkdirAll(subdir, 0755); err != nil { |
| 114 | return err |
| 115 | } |
| 116 | yaml := `name: my-plugin |
| 117 | version: 1.0.0 |
| 118 | usage: test |
| 119 | description: test` |
| 120 | return os.WriteFile(filepath.Join(subdir, "plugin.yaml"), []byte(yaml), 0644) |
| 121 | }, |
| 122 | pluginRoot: "my-plugin", |
| 123 | expectedName: "my-plugin", |
| 124 | expectError: false, |
| 125 | }, |
| 126 | { |
| 127 | name: "different directory and plugin name", |
| 128 | setup: func(dir string) error { |
| 129 | subdir := filepath.Join(dir, "wrong-name") |
| 130 | if err := os.MkdirAll(subdir, 0755); err != nil { |
| 131 | return err |
| 132 | } |
| 133 | yaml := `name: my-plugin |
| 134 | version: 1.0.0 |
| 135 | usage: test |
| 136 | description: test` |
| 137 | return os.WriteFile(filepath.Join(subdir, "plugin.yaml"), []byte(yaml), 0644) |
| 138 | }, |
| 139 | pluginRoot: "wrong-name", |
| 140 | expectedName: "wrong-name", |
| 141 | expectError: false, // Currently we don't error on mismatch |
| 142 | }, |
| 143 | } |
| 144 | |
| 145 | for _, tt := range tests { |
| 146 | t.Run(tt.name, func(t *testing.T) { |
| 147 | dir := t.TempDir() |
| 148 | if err := tt.setup(dir); err != nil { |
| 149 | t.Fatalf("Setup failed: %v", err) |
| 150 | } |
| 151 | |
| 152 | pluginRoot := filepath.Join(dir, tt.pluginRoot) |
| 153 | err := validatePluginName(pluginRoot, tt.expectedName) |
| 154 | if tt.expectError { |
| 155 | if err == nil { |
| 156 | t.Error("Expected error but got none") |
| 157 | } |
| 158 | } else { |
nothing calls this directly
no test coverage detected
searching dependent graphs…