kms_test.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package kms
  2. import (
  3. "context"
  4. "os"
  5. "reflect"
  6. "testing"
  7. "github.com/smallstep/certificates/kms/apiv1"
  8. "github.com/smallstep/certificates/kms/awskms"
  9. "github.com/smallstep/certificates/kms/cloudkms"
  10. "github.com/smallstep/certificates/kms/softkms"
  11. )
  12. func TestNew(t *testing.T) {
  13. ctx := context.Background()
  14. type args struct {
  15. ctx context.Context
  16. opts apiv1.Options
  17. }
  18. tests := []struct {
  19. name string
  20. skipOnCI bool
  21. args args
  22. want KeyManager
  23. wantErr bool
  24. }{
  25. {"softkms", false, args{ctx, apiv1.Options{Type: "softkms"}}, &softkms.SoftKMS{}, false},
  26. {"default", false, args{ctx, apiv1.Options{}}, &softkms.SoftKMS{}, false},
  27. {"awskms", false, args{ctx, apiv1.Options{Type: "awskms"}}, &awskms.KMS{}, false},
  28. {"cloudkms", true, args{ctx, apiv1.Options{Type: "cloudkms"}}, &cloudkms.CloudKMS{}, true}, // fails because not credentials
  29. {"pkcs11", false, args{ctx, apiv1.Options{Type: "pkcs11"}}, nil, true}, // not yet supported
  30. {"fail validation", false, args{ctx, apiv1.Options{Type: "foobar"}}, nil, true},
  31. }
  32. for _, tt := range tests {
  33. t.Run(tt.name, func(t *testing.T) {
  34. if tt.skipOnCI && os.Getenv("CI") == "true" {
  35. t.SkipNow()
  36. }
  37. got, err := New(tt.args.ctx, tt.args.opts)
  38. if (err != nil) != tt.wantErr {
  39. t.Errorf("New() error = %v, wantErr %v", err, tt.wantErr)
  40. return
  41. }
  42. if reflect.TypeOf(got) != reflect.TypeOf(tt.want) {
  43. t.Errorf("New() = %T, want %T", got, tt.want)
  44. }
  45. })
  46. }
  47. }