Skip to content

Commit

Permalink
use subtests
Browse files Browse the repository at this point in the history
  • Loading branch information
r2d4 committed Feb 20, 2017
1 parent a87c515 commit d49ce61
Showing 1 changed file with 22 additions and 23 deletions.
45 changes: 22 additions & 23 deletions pkg/util/crypto_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,28 +119,27 @@ func TestGenerateSignedCert(t *testing.T) {
}

for _, test := range tests {
t.Log(test.description)
err := GenerateSignedCert(certPath, keyPath, ips, alternateDNS, test.signerCertPath, test.signerKeyPath)
if err != nil && !test.err {
t.Errorf("GenerateSignedCert() error = %v", err)
continue
}
if err == nil && test.err {
t.Errorf("GenerateSignedCert() should have returned error, but didn't")
continue
}
if err != nil {
continue
}

certBytes, err := ioutil.ReadFile(certPath)
if err != nil {
t.Errorf("Error reading cert data: %v", err)
}
data, _ := pem.Decode(certBytes)
_, err = x509.ParseCertificate(data.Bytes)
if err != nil {
t.Errorf("Error parsing certificate: %v", err)
}
test := test
t.Run(test.description, func(t *testing.T) {
err := GenerateSignedCert(certPath, keyPath, ips, alternateDNS, test.signerCertPath, test.signerKeyPath)
if err != nil && !test.err {
t.Errorf("GenerateSignedCert() error = %v", err)
}
if err == nil && test.err {
t.Errorf("GenerateSignedCert() should have returned error, but didn't")
}
if err == nil {
certBytes, err := ioutil.ReadFile(certPath)
if err != nil {
t.Errorf("Error reading cert data: %v", err)
}
data, _ := pem.Decode(certBytes)
_, err = x509.ParseCertificate(data.Bytes)
if err != nil {
t.Errorf("Error parsing certificate: %v", err)
}
}

})
}
}

0 comments on commit d49ce61

Please sign in to comment.