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