2020-01-16 01:56:50 +00:00
|
|
|
package apiv1
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestOptions_Validate(t *testing.T) {
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
options *Options
|
|
|
|
wantErr bool
|
|
|
|
}{
|
|
|
|
{"nil", nil, false},
|
|
|
|
{"softkms", &Options{Type: "softkms"}, false},
|
|
|
|
{"cloudkms", &Options{Type: "cloudkms"}, false},
|
2020-05-20 00:45:15 +00:00
|
|
|
{"awskms", &Options{Type: "awskms"}, false},
|
2020-11-03 13:26:46 +00:00
|
|
|
{"sshagentkms", &Options{Type: "sshagentkms"}, false},
|
2021-01-27 04:03:53 +00:00
|
|
|
{"pkcs11", &Options{Type: "pkcs11"}, false},
|
2020-01-16 01:56:50 +00:00
|
|
|
{"unsupported", &Options{Type: "unsupported"}, true},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
if err := tt.options.Validate(); (err != nil) != tt.wantErr {
|
|
|
|
t.Errorf("Options.Validate() error = %v, wantErr %v", err, tt.wantErr)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestErrNotImplemented_Error(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
msg string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{"default", fields{}, "not implemented"},
|
|
|
|
{"custom", fields{"custom message: not implemented"}, "custom message: not implemented"},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
e := ErrNotImplemented{
|
2021-01-28 04:23:45 +00:00
|
|
|
Message: tt.fields.msg,
|
2020-01-16 01:56:50 +00:00
|
|
|
}
|
|
|
|
if got := e.Error(); got != tt.want {
|
|
|
|
t.Errorf("ErrNotImplemented.Error() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
2021-02-01 22:25:49 +00:00
|
|
|
|
|
|
|
func TestErrAlreadyExists_Error(t *testing.T) {
|
|
|
|
type fields struct {
|
|
|
|
msg string
|
|
|
|
}
|
|
|
|
tests := []struct {
|
|
|
|
name string
|
|
|
|
fields fields
|
|
|
|
want string
|
|
|
|
}{
|
|
|
|
{"default", fields{}, "key already exists"},
|
|
|
|
{"custom", fields{"custom message: key already exists"}, "custom message: key already exists"},
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
|
|
e := ErrAlreadyExists{
|
|
|
|
Message: tt.fields.msg,
|
|
|
|
}
|
|
|
|
if got := e.Error(); got != tt.want {
|
|
|
|
t.Errorf("ErrAlreadyExists.Error() = %v, want %v", got, tt.want)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|