(t *testing.T)
| 326 | } |
| 327 | |
| 328 | func Test_encryptedKeyFromSecret(t *testing.T) { |
| 329 | tests := []struct { |
| 330 | name string |
| 331 | secret *api.Secret |
| 332 | want string |
| 333 | wantErr bool |
| 334 | }{ |
| 335 | {name: "nil secret", secret: nil, wantErr: true}, |
| 336 | {name: "secret with nil data", secret: &api.Secret{Data: nil}, wantErr: true}, |
| 337 | {name: "secret without ciphertext data", secret: &api.Secret{Data: map[string]interface{}{"other": true}}, wantErr: true}, |
| 338 | {name: "ciphertext non string", secret: &api.Secret{Data: map[string]interface{}{"ciphertext": 123}}, wantErr: true}, |
| 339 | {name: "ciphertext data", secret: &api.Secret{Data: map[string]interface{}{"ciphertext": "secret string"}}, want: "secret string"}, |
| 340 | } |
| 341 | for _, tt := range tests { |
| 342 | t.Run(tt.name, func(t *testing.T) { |
| 343 | got, err := encryptedKeyFromSecret(tt.secret) |
| 344 | if tt.wantErr { |
| 345 | assert.Error(t, err) |
| 346 | assert.Empty(t, got) |
| 347 | return |
| 348 | } |
| 349 | assert.NoError(t, err) |
| 350 | assert.Equal(t, tt.want, got) |
| 351 | }) |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | func Test_dataKeyFromSecret(t *testing.T) { |
| 356 | tests := []struct { |
nothing calls this directly
no test coverage detected