Skip to content

Commit

Permalink
Converting Errorf to Fatalf
Browse files Browse the repository at this point in the history
  • Loading branch information
madflojo committed Oct 21, 2023
1 parent e59904c commit f7b6a75
Showing 1 changed file with 8 additions and 13 deletions.
21 changes: 8 additions & 13 deletions testcerts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ func TestCertsUsage(t *testing.T) {
t.Run("Write to File", func(t *testing.T) {
tempDir, err := os.MkdirTemp("", "")
if err != nil {
t.Errorf("Error creating temporary directory: %s", err)
return
t.Fatalf("Error creating temporary directory: %s", err)
}
defer os.RemoveAll(tempDir)

Expand All @@ -41,19 +40,19 @@ func TestCertsUsage(t *testing.T) {

err = ca.ToFile(certPath, keyPath)
if err != nil {
t.Errorf("Error while generating certificates to files - %s", err)
t.Fatalf("Error while generating certificates to files - %s", err)
}

// Check if Cert file exists
_, err = os.Stat(certPath)
if err != nil {
t.Errorf("Error while generating certificates to files file error - %s", err)
t.Fatalf("Error while generating certificates to files file error - %s", err)
}

// Check if Key file exists
_, err = os.Stat(keyPath)
if err != nil {
t.Errorf("Error while generating certificates to files file error - %s", err)
t.Fatalf("Error while generating certificates to files file error - %s", err)
}
})

Expand Down Expand Up @@ -121,8 +120,7 @@ func TestCertsUsage(t *testing.T) {
t.Run("Write to File", func(t *testing.T) {
tempDir, err := os.MkdirTemp("", "")
if err != nil {
t.Errorf("Error creating temporary directory: %s", err)
return
t.Fatalf("Error creating temporary directory: %s", err)
}
defer os.RemoveAll(tempDir)

Expand Down Expand Up @@ -348,15 +346,13 @@ func testUsingCerts(t *testing.T, rootCAs func(ca *CertificateAuthority, certs *
ca := NewCA()
certs, err := ca.NewKeyPair("localhost")
if err != nil {
t.Errorf("Error generating keypair - %s", err)
return
t.Fatalf("Error generating keypair - %s", err)
}

// Write certificates to a file
cert, key, err := certs.ToTempFile("")
if err != nil {
t.Errorf("Error writing certs to temp files - %s", err)
return
t.Fatalf("Error writing certs to temp files - %s", err)
}

// Create HTTP Server
Expand All @@ -379,8 +375,7 @@ func testUsingCerts(t *testing.T, rootCAs func(ca *CertificateAuthority, certs *
// Setup HTTP Client with Cert Pool
certpool := rootCAs(ca, certs)
if certpool == nil {
t.Error("Test configuration error: rootCAs arg function returned nil instead of a x509.CertPool")
return
t.Fatalf("Test configuration error: rootCAs arg function returned nil instead of a x509.CertPool")
}
client := &http.Client{
Transport: &http.Transport{
Expand Down

0 comments on commit f7b6a75

Please sign in to comment.