cleaning up tests by converting t.Fatal to assert.___

Signed-off-by: David Lawrence <david.lawrence@docker.com> (github: endophage)
This commit is contained in:
David Lawrence 2015-12-22 13:58:29 -08:00 committed by Ying Li
parent f2ec72b5b6
commit e516dd88f2
3 changed files with 19 additions and 33 deletions

View File

@ -1064,12 +1064,10 @@ func testValidateRootKey(t *testing.T, rootType string) {
assert.NotEmpty(t, keyids)
for _, keyid := range keyids {
if key, ok := decodedRoot.Keys[keyid]; !ok {
t.Fatal("key id not found in keys")
} else {
_, err := trustmanager.LoadCertFromPEM(key.Public())
assert.NoError(t, err, "key is not a valid cert")
}
key, ok := decodedRoot.Keys[keyid]
assert.True(t, ok, "key id not found in keys")
_, err := trustmanager.LoadCertFromPEM(key.Public())
assert.NoError(t, err, "key is not a valid cert")
}
}

View File

@ -93,9 +93,7 @@ func TestImportExportZip(t *testing.T) {
// exist and are encrypted with the expected passphrase.
for _, f := range zipReader.File {
expectedPassphrase, present := passphraseByFile[f.Name]
if !present {
t.Fatalf("unexpected file %s in zip file", f.Name)
}
assert.True(t, present, "unexpected file %s in zip file", f.Name)
delete(passphraseByFile, f.Name)
@ -114,9 +112,7 @@ func TestImportExportZip(t *testing.T) {
zipReader.Close()
// Are there any keys that didn't make it to the zip?
for fileNotFound := range passphraseByFile {
t.Fatalf("%s not found in zip", fileNotFound)
}
assert.Len(t, passphraseByFile, 0)
// Create new repo to test import
tempBaseDir2, err := ioutil.TempDir("", "notary-test-")
@ -199,9 +195,7 @@ func TestImportExportGUN(t *testing.T) {
privKeyMap := cs.ListAllKeys()
for privKeyName := range privKeyMap {
_, alias, err := cs.GetPrivateKey(privKeyName)
if err != nil {
t.Fatalf("privKey %s has no alias", privKeyName)
}
assert.NoError(t, err, "privKey %s has no alias", privKeyName)
if alias == "root" {
continue
}
@ -215,9 +209,7 @@ func TestImportExportGUN(t *testing.T) {
for _, f := range zipReader.File {
expectedPassphrase, present := passphraseByFile[f.Name]
if !present {
t.Fatalf("unexpected file %s in zip file", f.Name)
}
assert.True(t, present, "unexpected file %s in zip file", f.Name)
delete(passphraseByFile, f.Name)
@ -236,9 +228,7 @@ func TestImportExportGUN(t *testing.T) {
zipReader.Close()
// Are there any keys that didn't make it to the zip?
for fileNotFound := range passphraseByFile {
t.Fatalf("%s not found in zip", fileNotFound)
}
assert.Len(t, passphraseByFile, 0)
// Create new repo to test import
tempBaseDir2, err := ioutil.TempDir("", "notary-test-")
@ -264,9 +254,7 @@ func TestImportExportGUN(t *testing.T) {
continue
}
_, alias, err := cs2.GetPrivateKey(privKeyName)
if err != nil {
t.Fatalf("privKey %s has no alias", privKeyName)
}
assert.NoError(t, err, "privKey %s has no alias", privKeyName)
if alias == "root" {
continue
}

View File

@ -25,9 +25,7 @@ func TestRunBadAddr(t *testing.T) {
"",
nil,
)
if err == nil {
t.Fatal("Passed bad addr, Run should have failed")
}
assert.Error(t, err, "Passed bad addr, Run should have failed")
}
func TestRunReservedPort(t *testing.T) {
@ -42,12 +40,14 @@ func TestRunReservedPort(t *testing.T) {
nil,
)
if _, ok := err.(*net.OpError); !ok {
t.Fatalf("Received unexpected err: %s", err.Error())
}
if !strings.Contains(err.Error(), "bind: permission denied") {
t.Fatalf("Received unexpected err: %s", err.Error())
}
assert.Error(t, err)
assert.IsType(t, &net.OpError{}, err)
assert.True(
t,
strings.Contains(err.Error(), "bind: permission denied"),
"Received unexpected err: %s",
err.Error(),
)
}
func TestMetricsEndpoint(t *testing.T) {