1package structs 2 3import ( 4 "testing" 5 "time" 6 7 "github.com/stretchr/testify/require" 8) 9 10func TestCAConfiguration_GetCommonConfig(t *testing.T) { 11 tests := []struct { 12 name string 13 cfg *CAConfiguration 14 want *CommonCAProviderConfig 15 wantErr bool 16 }{ 17 { 18 name: "basic defaults", 19 cfg: &CAConfiguration{ 20 Config: map[string]interface{}{ 21 "RotationPeriod": "2160h", 22 "LeafCertTTL": "72h", 23 }, 24 }, 25 want: &CommonCAProviderConfig{ 26 LeafCertTTL: 72 * time.Hour, 27 }, 28 }, 29 { 30 // Note that this is currently what is actually stored in MemDB, I think 31 // due to a trip through msgpack somewhere but I'm not really sure why 32 // since the defaults are applied on the server and so should probably use 33 // direct RPC that bypasses encoding? Either way this case is important 34 // because it reflects the actual data as it's stored in state which is 35 // what matters in real life. 36 name: "basic defaults after encoding fun", 37 cfg: &CAConfiguration{ 38 Config: map[string]interface{}{ 39 "RotationPeriod": []uint8("2160h"), 40 "LeafCertTTL": []uint8("72h"), 41 }, 42 }, 43 want: &CommonCAProviderConfig{ 44 LeafCertTTL: 72 * time.Hour, 45 }, 46 }, 47 } 48 for _, tt := range tests { 49 t.Run(tt.name, func(t *testing.T) { 50 got, err := tt.cfg.GetCommonConfig() 51 if (err != nil) != tt.wantErr { 52 t.Errorf("CAConfiguration.GetCommonConfig() error = %v, wantErr %v", err, tt.wantErr) 53 return 54 } 55 require.Equal(t, tt.want, got) 56 }) 57 } 58} 59