Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit cade4a1

Browse files
committedOct 10, 2024·
Fix lint errors and condition evaluation in tests
1 parent 512866f commit cade4a1

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed
 

‎conformance/tests/backendtlspolicy.go

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"testing"
2121

2222
"k8s.io/apimachinery/pkg/types"
23+
2324
"sigs.k8s.io/gateway-api/conformance/utils/http"
2425
"sigs.k8s.io/gateway-api/conformance/utils/kubernetes"
2526
"sigs.k8s.io/gateway-api/conformance/utils/suite"

‎conformance/utils/kubernetes/certificate.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func generateRSACert(hosts []string, keyOut, certOut io.Writer) error {
9999
for _, h := range hosts {
100100
if ip := net.ParseIP(h); ip != nil {
101101
template.IPAddresses = append(template.IPAddresses, ip)
102-
} else if err := validateHost(h); err == nil {
102+
} else if err = validateHost(h); err == nil {
103103
template.DNSNames = append(template.DNSNames, h)
104104
}
105105
}

‎conformance/utils/kubernetes/certificate_test.go

+12-12
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func Test_generateCACert(t *testing.T) {
2929
tests := []struct {
3030
name string
3131
hosts []string
32-
expectedErr string
32+
expectedErr []string
3333
}{
3434
{
3535
name: "one host generates cert with no host",
@@ -50,12 +50,12 @@ func Test_generateCACert(t *testing.T) {
5050
{
5151
name: "bad host generates cert for no host",
5252
hosts: []string{"--abc.example.com"},
53-
expectedErr: "x509: certificate is not valid for any names, but wanted to match --abc.example.com",
53+
expectedErr: []string{"x509: certificate is not valid for any names, but wanted to match --abc.example.com"},
5454
},
5555
{
5656
name: "one good host and one bad host generates cert for only good host",
5757
hosts: []string{"---.example.com", "def.example.com"},
58-
expectedErr: "x509: certificate is valid for def.example.com, not ---.example.com",
58+
expectedErr: []string{"x509: certificate is valid xxx for def.example.com, not ---.example.com", ""},
5959
},
6060
}
6161

@@ -74,24 +74,24 @@ func Test_generateCACert(t *testing.T) {
7474
block, _ := pem.Decode(serverCert.Bytes())
7575
if block == nil {
7676
require.FailNow(t, "failed to decode PEM block containing cert")
77-
}
78-
if block.Type == "CERTIFICATE" {
77+
} else if block.Type == "CERTIFICATE" {
7978
cert, err := x509.ParseCertificate(block.Bytes)
8079
require.NoError(t, err, "failed to parse certificate")
81-
for _, h := range tc.hosts {
82-
if err = cert.VerifyHostname(h); err != nil {
83-
require.EqualValues(t, tc.expectedErr, err.Error(), "certificate verification failed")
84-
} else if len(tc.hosts) < 2 && err == nil && tc.expectedErr != "" {
85-
require.EqualValues(t, tc.expectedErr, nil, "expected an error but certification verification succeeded")
80+
for idx, h := range tc.hosts {
81+
err = cert.VerifyHostname(h)
82+
if err != nil && len(tc.expectedErr) > 0 && tc.expectedErr[idx] == "" {
83+
require.EqualValues(t, tc.expectedErr[idx], err.Error(), "certificate verification failed")
84+
} else if err == nil && len(tc.expectedErr) > 0 && tc.expectedErr[idx] != "" {
85+
require.EqualValues(t, tc.expectedErr[idx], err, "expected an error but certification verification succeeded")
8686
}
8787
}
8888
}
89+
8990
// Test that the server key is decodable and parseable.
9091
block, _ = pem.Decode(serverKey.Bytes())
9192
if block == nil {
9293
require.FailNow(t, "failed to decode PEM block containing public key")
93-
}
94-
if block.Type == "RSA PRIVATE KEY" {
94+
} else if block.Type == "RSA PRIVATE KEY" {
9595
_, err := x509.ParsePKCS1PrivateKey(block.Bytes)
9696
require.NoError(t, err, "failed to parse key")
9797
}

0 commit comments

Comments
 (0)
Please sign in to comment.