2021-03-18 12:47:16 +00:00
|
|
|
/*
|
|
|
|
Copyright 2021 The Ceph-CSI Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-08-26 11:43:20 +00:00
|
|
|
package kms
|
2021-03-18 12:47:16 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2024-04-04 08:55:00 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2021-03-18 12:47:16 +00:00
|
|
|
)
|
|
|
|
|
2021-08-26 11:43:20 +00:00
|
|
|
func noinitKMS(args ProviderInitArgs) (EncryptionKMS, error) {
|
2021-03-18 12:47:16 +00:00
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
2021-08-26 11:43:20 +00:00
|
|
|
func TestRegisterProvider(t *testing.T) {
|
2021-06-02 09:55:53 +00:00
|
|
|
t.Parallel()
|
2021-03-18 12:47:16 +00:00
|
|
|
tests := []struct {
|
2021-08-26 11:43:20 +00:00
|
|
|
provider Provider
|
2021-03-18 12:47:16 +00:00
|
|
|
panics bool
|
|
|
|
}{{
|
2021-08-26 11:43:20 +00:00
|
|
|
Provider{
|
2021-03-18 12:47:16 +00:00
|
|
|
UniqueID: "incomplete-provider",
|
|
|
|
},
|
|
|
|
true,
|
|
|
|
}, {
|
2021-08-26 11:43:20 +00:00
|
|
|
Provider{
|
2021-03-18 12:47:16 +00:00
|
|
|
UniqueID: "initializer-only",
|
|
|
|
Initializer: noinitKMS,
|
|
|
|
},
|
|
|
|
false,
|
|
|
|
}}
|
|
|
|
|
|
|
|
for _, test := range tests {
|
|
|
|
provider := test.provider
|
|
|
|
if test.panics {
|
2024-04-04 08:55:00 +00:00
|
|
|
require.Panics(t, func() { RegisterProvider(provider) })
|
2021-03-18 12:47:16 +00:00
|
|
|
} else {
|
2024-04-04 08:55:00 +00:00
|
|
|
require.True(t, RegisterProvider(provider))
|
2021-03-18 12:47:16 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|