kms_test.go 1.4 KB

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