2020-04-25 22:22:45 +00:00
|
|
|
package cert
|
|
|
|
|
|
|
|
import (
|
|
|
|
"reflect"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Test_certOptionsDefaulter(t *testing.T) {
|
2021-02-10 20:26:45 +00:00
|
|
|
type testCase struct {
|
2020-04-25 22:22:45 +00:00
|
|
|
name string
|
|
|
|
arg GenerationOptions
|
|
|
|
expected GenerationOptions
|
2021-02-10 20:26:45 +00:00
|
|
|
}
|
|
|
|
tests := []testCase{
|
2020-04-25 22:22:45 +00:00
|
|
|
{
|
2021-02-10 20:26:45 +00:00
|
|
|
name: "Empty options",
|
2020-04-25 22:22:45 +00:00
|
|
|
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{""},
|
|
|
|
},
|
|
|
|
},
|
2021-02-10 20:26:45 +00:00
|
|
|
{
|
|
|
|
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{""},
|
|
|
|
},
|
|
|
|
},
|
2020-04-25 22:22:45 +00:00
|
|
|
}
|
2021-02-10 20:26:45 +00:00
|
|
|
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)
|
|
|
|
}
|
2020-04-25 22:22:45 +00:00
|
|
|
if !reflect.DeepEqual(tt.expected, tt.arg) {
|
|
|
|
t.Errorf("Apply defaulter expected=%v got=%v", tt.expected, tt.arg)
|
|
|
|
}
|
2021-02-10 20:26:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, tt := range tests {
|
|
|
|
t.Run(tt.name, scenario(tt))
|
2020-04-25 22:22:45 +00:00
|
|
|
}
|
|
|
|
}
|