Skip to content
This repository has been archived by the owner on Jul 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2632 from draychev/small-refactor-to-sds-tests
Browse files Browse the repository at this point in the history
sds: Carve out new testCase struct type
  • Loading branch information
draychev authored Feb 26, 2021
2 parents 87e6c97 + 33225d3 commit 5c137bd
Showing 1 changed file with 20 additions and 10 deletions.
30 changes: 20 additions & 10 deletions pkg/envoy/sds/response_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func TestGetRootCert(t *testing.T) {

mockCertManager := certificate.NewMockManager(mockCtrl)

testCases := []struct {
type testCase struct {
name string
sdsCert envoy.SDSCert
proxyService service.MeshService
Expand All @@ -40,7 +40,9 @@ func TestGetRootCert(t *testing.T) {
// expectations
expectedSANs []string
expectError bool
}{
}

testCases := []testCase{
// Test case 1: tests SDS secret for inbound TLS secret -------------------------------
{
name: "test inbound MTLS certificate validation",
Expand Down Expand Up @@ -162,12 +164,14 @@ func TestGetServiceCert(t *testing.T) {

mockCertificater := certificate.NewMockCertificater(mockCtrl)

testCases := []struct {
type testCase struct {
certName string
certChain []byte
privKey []byte
expectError bool
}{
}

testCases := []testCase{
{"foo", []byte("cert-chain"), []byte("priv-key"), false},
{"bar", []byte("cert-chain-2"), []byte("priv-key-2"), false},
}
Expand Down Expand Up @@ -202,7 +206,7 @@ func TestGetSDSSecrets(t *testing.T) {
mockCertificater *certificate.MockCertificater
}

testCases := []struct {
type testCase struct {
name string
proxyService service.MeshService
proxySvcAccount service.K8sServiceAccount
Expand All @@ -220,7 +224,9 @@ func TestGetSDSSecrets(t *testing.T) {
// expectations
expectedSANs []string // only set for service-cert
expectedSecretCount int
}{
}

testCases := []testCase{
// Test case 1: root-cert-for-mtls-inbound requested -------------------------------
{
name: "test root-cert-for-mtls-inbound cert type request",
Expand Down Expand Up @@ -393,10 +399,12 @@ func TestGetSDSSecrets(t *testing.T) {
func TestGetSubjectAltNamesFromSvcAccount(t *testing.T) {
assert := tassert.New(t)

testCases := []struct {
type testCase struct {
svcAccounts []service.K8sServiceAccount
expectedSANMatchers []*xds_matcher.StringMatcher
}{
}

testCases := []testCase{
{
svcAccounts: []service.K8sServiceAccount{
{Name: "sa-1", Namespace: "ns-1"},
Expand Down Expand Up @@ -428,10 +436,12 @@ func TestGetSubjectAltNamesFromSvcAccount(t *testing.T) {
func TestSubjectAltNamesToStr(t *testing.T) {
assert := tassert.New(t)

testCases := []struct {
type testCase struct {
sanMatchers []*xds_matcher.StringMatcher
strSANs []string
}{
}

testCases := []testCase{
{
sanMatchers: []*xds_matcher.StringMatcher{
{
Expand Down

0 comments on commit 5c137bd

Please sign in to comment.