e2e: use testify requires instead of t.Fatal

testify requires offer better error message that is easier to notice when seeing
a wall of text in the builds.
This commit is contained in:
Mahmood Ali
2021-01-26 09:14:47 -05:00
parent 30573f048e
commit f7acda4260
7 changed files with 21 additions and 21 deletions

View File

@@ -176,7 +176,7 @@ func (tc *ConsulE2ETest) TestCanaryInplaceUpgrades(f *framework.F) {
return true, nil
}, func(err error) {
t.Fatalf("error while waiting for deploys: %v", err)
require.NoError(t, err, "error while waiting for deploys")
})
allocID := activeDeploy.TaskGroups["consul_canary_test"].PlacedCanaries[0]
@@ -196,7 +196,7 @@ func (tc *ConsulE2ETest) TestCanaryInplaceUpgrades(f *framework.F) {
return *alloc.DeploymentStatus.Healthy, fmt.Errorf("expected healthy canary but found: %#v",
alloc.DeploymentStatus)
}, func(err error) {
t.Fatalf("error waiting for canary to be healthy: %v", err)
require.NoError(t, err, "error waiting for canary to be healthy")
})
// Check Consul for canary tags
@@ -212,7 +212,7 @@ func (tc *ConsulE2ETest) TestCanaryInplaceUpgrades(f *framework.F) {
}
return false, fmt.Errorf(`could not find service tags {"canary", "foo"}: %#v`, consulServices)
}, func(err error) {
t.Fatalf("error waiting for canary tags: %v", err)
require.NoError(t, err, "error waiting for canary tags")
})
// Promote canary
@@ -230,7 +230,7 @@ func (tc *ConsulE2ETest) TestCanaryInplaceUpgrades(f *framework.F) {
}
return !alloc.DeploymentStatus.Canary, fmt.Errorf("still a canary")
}, func(err error) {
t.Fatalf("error waiting for canary to be promoted: %v", err)
require.NoError(t, err, "error waiting for canary to be promoted")
})
// Verify that no instances have canary tags
@@ -248,7 +248,7 @@ func (tc *ConsulE2ETest) TestCanaryInplaceUpgrades(f *framework.F) {
}
return true, nil
}, func(err error) {
t.Fatalf("error waiting for non-canary tags: %v", err)
require.NoError(t, err, "error waiting for non-canary tags")
})
}

View File

@@ -277,7 +277,7 @@ func (tc *ConsulTemplateTest) TestTemplatePathInterpolation_Bad(f *framework.F)
return alloc.ClientStatus == structs.AllocClientStatusFailed, fmt.Errorf("expected status failed, but was: %s", alloc.ClientStatus)
}, func(err error) {
f.T().Fatalf("failed to wait on alloc: %v", err)
f.NoError(err, "failed to wait on alloc")
})
// Assert the "source escapes" error occurred to prevent false

View File

@@ -116,7 +116,7 @@ func (j *e2eServiceJob) Run(f *framework.F) {
return alloc.ClientStatus == structs.AllocClientStatusRunning, fmt.Errorf("expected status running, but was: %s", alloc.ClientStatus)
}, func(err error) {
t.Fatalf("failed to keep alloc running: %v", err)
require.NoError(t, err, "failed to keep alloc running")
})
scriptPath := filepath.Join(filepath.Dir(j.jobfile), j.script)

View File

@@ -7,6 +7,8 @@ import (
"reflect"
"strings"
"testing"
"github.com/stretchr/testify/require"
)
const frameworkHelp = `
@@ -119,7 +121,7 @@ func AddSuites(s ...*TestSuite) {
func (f *Framework) Run(t *testing.T) {
info, err := f.provisioner.SetupTestRun(t, SetupOptions{})
if err != nil {
t.Fatalf("could not provision cluster: %v", err)
require.NoError(t, err, "could not provision cluster")
}
defer f.provisioner.TearDownTestRun(t, info.ID)
@@ -178,9 +180,7 @@ func (f *Framework) runSuite(t *testing.T, s *TestSuite) (skip bool, err error)
ExpectConsul: s.Consul,
ExpectVault: s.Vault,
})
if err != nil {
t.Fatalf("could not provision cluster: %v", err)
}
require.NoError(t, err, "could not provision cluster")
defer f.provisioner.TearDownTestSuite(t, info.ID)
for _, c := range s.Cases {

View File

@@ -102,7 +102,7 @@ func (tc *LifecycleE2ETest) TestServiceJob(f *framework.F) {
return true, nil
}, func(err error) {
t.Fatalf("failed to wait on alloc: %v", err)
require.NoError(err, "failed to wait on alloc")
})
alloc, _, err := nomadClient.Allocations().Info(allocID, nil)

View File

@@ -107,7 +107,7 @@ func (tc *TaskEventsTest) waitUntilEvents(f *framework.F, jobName string, numEve
return true, nil
}, func(err error) {
t.Fatalf("task events error: %v", err)
require.NoError(t, err, "task events error")
})
return alloc, taskState

View File

@@ -62,7 +62,7 @@ func syncVault(t *testing.T) ([]*version.Version, map[string]string) {
case err := <-errCh:
require.NoError(t, err)
case <-time.After(5 * time.Minute):
t.Fatalf("timed out downloading Vault binaries")
require.Fail(t, "timed out downloading Vault binaries")
}
}
if n := len(missing); n > 0 {
@@ -361,7 +361,7 @@ func testVaultCompatibility(t *testing.T, vault string, version string) {
case 1:
default:
// exit early
t.Fatalf("too many allocations; something failed")
require.Fail("too many allocations; something failed")
}
alloc := allocs[0]
//allocID = alloc.ID
@@ -371,7 +371,7 @@ func testVaultCompatibility(t *testing.T, vault string, version string) {
return false, fmt.Errorf("client status %q", alloc.ClientStatus)
}, func(err error) {
t.Fatalf("allocation did not finish: %v", err)
require.NoError(err, "allocation did not finish")
})
}
@@ -392,14 +392,14 @@ func setupVault(t *testing.T, client *vapi.Client, vaultVersion string) string {
}
request := client.NewRequest("PUT", "/v1/sys/policy/nomad-server")
if err := request.SetJSONBody(body); err != nil {
t.Fatalf("failed to set JSON body on legacy policy creation: %v", err)
require.NoError(t, err, "failed to set JSON body on legacy policy creation")
}
if _, err := client.RawRequest(request); err != nil {
t.Fatalf("failed to create legacy policy: %v", err)
require.NoError(t, err, "failed to create legacy policy")
}
} else {
if err := sys.PutPolicy("nomad-server", policy); err != nil {
t.Fatalf("failed to create policy: %v", err)
require.NoError(t, err, "failed to create policy")
}
}
@@ -416,12 +416,12 @@ func setupVault(t *testing.T, client *vapi.Client, vaultVersion string) string {
}
s, err := a.Create(&req)
if err != nil {
t.Fatalf("failed to create child token: %v", err)
require.NoError(t, err, "failed to create child token")
}
// Get the client token
if s == nil || s.Auth == nil {
t.Fatalf("bad secret response: %+v", s)
require.NoError(t, err, "bad secret response")
}
return s.Auth.ClientToken