Skip to content

Commit

Permalink
refactor: t.Error + return -> t.Fatal
Browse files Browse the repository at this point in the history
  • Loading branch information
hhsnopek committed Oct 22, 2022
1 parent 0cd9d80 commit 304f44c
Showing 1 changed file with 8 additions and 16 deletions.
24 changes: 8 additions & 16 deletions wait/http_test.go
Expand Up @@ -48,21 +48,18 @@ func ExampleHTTPStrategy() {
func TestHTTPStrategyWaitUntilReady(t *testing.T) {
workdir, err := os.Getwd()
if err != nil {
t.Error(err)
return
t.Fatal(err)
}

capath := path.Join(workdir, "testdata", "root.pem")
cafile, err := os.ReadFile(capath)
if err != nil {
t.Errorf("can't load ca file: %v", err)
return
t.Fatalf("can't load ca file: %v", err)
}

certpool := x509.NewCertPool()
if !certpool.AppendCertsFromPEM(cafile) {
t.Errorf("the ca file isn't valid")
return
t.Fatalf("the ca file isn't valid")
}

tlsconfig := &tls.Config{RootCAs: certpool, ServerName: "testcontainer.go.test"}
Expand All @@ -88,20 +85,17 @@ func TestHTTPStrategyWaitUntilReady(t *testing.T) {
ctx := context.Background()
container, err := testcontainers.GenericContainer(ctx, testcontainers.GenericContainerRequest{ContainerRequest: dockerReq, Started: true})
if err != nil {
t.Error(err)
return
t.Fatal(err)
}
testcontainers.CleanupContainer(t, ctx, container)

host, err := container.Host(ctx)
if err != nil {
t.Error(err)
return
t.Fatal(err)
}
port, err := container.MappedPort(ctx, "6443/tcp")
if err != nil {
t.Error(err)
return
t.Fatal(err)
}
client := http.Client{
Transport: &http.Transport{
Expand All @@ -121,12 +115,10 @@ func TestHTTPStrategyWaitUntilReady(t *testing.T) {
}
resp, err := client.Get(fmt.Sprintf("https://%s:%s", host, port.Port()))
if err != nil {
t.Error(err)
return
t.Fatal(err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
t.Errorf("status code isn't ok: %s", resp.Status)
return
t.Fatalf("status code isn't ok: %s", resp.Status)
}
}

0 comments on commit 304f44c

Please sign in to comment.