api/pkg/cert/defaults_test.go
Peter Kurfer d70ba748f5 Introduce Lifecycle for every endpoint and manage listeners in the renamed Orchestrator
- merge packages to get a more concise layout because plugins are no more and therefore there's not a lot to be exported
- fix test logger
- rework config parsing to be easier and more transparent
- remove unnecessary APIs because dynamic endpoint handling is rather a won't implement
2021-02-10 20:26:45 +00:00

76 lines
1.9 KiB
Go

package cert
import (
"reflect"
"testing"
)
func Test_certOptionsDefaulter(t *testing.T) {
type testCase struct {
name string
arg GenerationOptions
expected GenerationOptions
}
tests := []testCase{
{
name: "Empty options",
arg: GenerationOptions{
CommonName: "CA",
},
expected: GenerationOptions{
CommonName: "CA",
Country: []string{"US"},
Locality: []string{"San Francisco"},
Organization: []string{"INetMock"},
StreetAddress: []string{"Golden Gate Bridge"},
PostalCode: []string{"94016"},
Province: []string{""},
},
},
{
name: "Options with country set",
arg: GenerationOptions{
CommonName: "CA",
Country: []string{"DE"},
},
expected: GenerationOptions{
CommonName: "CA",
Country: []string{"DE"},
Locality: []string{"San Francisco"},
Organization: []string{"INetMock"},
StreetAddress: []string{"Golden Gate Bridge"},
PostalCode: []string{"94016"},
Province: []string{""},
},
},
{
name: "Options with organization set set",
arg: GenerationOptions{
CommonName: "CA",
Organization: []string{"inetmock"},
},
expected: GenerationOptions{
CommonName: "CA",
Country: []string{"US"},
Locality: []string{"San Francisco"},
Organization: []string{"inetmock"},
StreetAddress: []string{"Golden Gate Bridge"},
PostalCode: []string{"94016"},
Province: []string{""},
},
},
}
scenario := func(tt testCase) func(t *testing.T) {
return func(t *testing.T) {
if err := applyDefaultGenerationOptions(&tt.arg); err != nil {
t.Errorf("applyDefaultGenerationOptions() error = %v", err)
}
if !reflect.DeepEqual(tt.expected, tt.arg) {
t.Errorf("Apply defaulter expected=%v got=%v", tt.expected, tt.arg)
}
}
}
for _, tt := range tests {
t.Run(tt.name, scenario(tt))
}
}