(t *testing.T)
| 207 | } |
| 208 | |
| 209 | func TestPublicKeyFromKeyRef(t *testing.T) { |
| 210 | tests := []struct { |
| 211 | name string |
| 212 | keyRef string |
| 213 | setup func(fs afero.Fs, ctx context.Context) |
| 214 | expectErr bool |
| 215 | errMsg string |
| 216 | }{ |
| 217 | { |
| 218 | name: "file path", |
| 219 | keyRef: "/path/to/public-key.pem", |
| 220 | setup: func(fs afero.Fs, ctx context.Context) { |
| 221 | err := afero.WriteFile(fs, "/path/to/public-key.pem", []byte("test public key content"), 0o600) |
| 222 | require.NoError(t, err) |
| 223 | }, |
| 224 | expectErr: false, |
| 225 | }, |
| 226 | { |
| 227 | name: "k8s secret with explicit key field", |
| 228 | keyRef: "k8s://test-namespace/test-secret/public-key", |
| 229 | setup: func(fs afero.Fs, ctx context.Context) { |
| 230 | // This will be handled in the test loop |
| 231 | }, |
| 232 | expectErr: false, |
| 233 | }, |
| 234 | { |
| 235 | name: "k8s secret with single key (auto-select)", |
| 236 | keyRef: "k8s://test-namespace/single-key-secret", |
| 237 | setup: func(fs afero.Fs, ctx context.Context) { |
| 238 | // This will be handled in the test loop |
| 239 | }, |
| 240 | expectErr: false, |
| 241 | }, |
| 242 | { |
| 243 | name: "k8s secret with multiple keys (no key field specified)", |
| 244 | keyRef: "k8s://test-namespace/multi-key-secret", |
| 245 | setup: func(fs afero.Fs, ctx context.Context) { |
| 246 | // This will be handled in the test loop |
| 247 | }, |
| 248 | expectErr: true, |
| 249 | errMsg: "contains multiple keys, please specify the key field", |
| 250 | }, |
| 251 | { |
| 252 | name: "invalid k8s format", |
| 253 | keyRef: "k8s://invalid-format", |
| 254 | setup: func(fs afero.Fs, ctx context.Context) {}, |
| 255 | expectErr: true, |
| 256 | errMsg: "invalid k8s key reference format", |
| 257 | }, |
| 258 | { |
| 259 | name: "file not found", |
| 260 | keyRef: "/nonexistent/public-key.pem", |
| 261 | setup: func(fs afero.Fs, ctx context.Context) {}, |
| 262 | expectErr: true, |
| 263 | errMsg: "read key from file", |
| 264 | }, |
| 265 | } |
| 266 |
nothing calls this directly
no test coverage detected