Remove panic() and handle it appropriately (#5807)

This is an effort to remove panic from the source. 
Add a new call called CriticialIf, that calls LogIf and exits. 
Replace panics with one of CriticalIf, FatalIf and a return of error.
This commit is contained in:
ebozduman
2018-04-19 17:24:43 -07:00
committed by kannappanr
parent 846f3e8f59
commit f16bfda2f2
21 changed files with 129 additions and 128 deletions

View File

@@ -54,8 +54,11 @@ func TestIsSecretKeyValid(t *testing.T) {
}
}
func TestMustGetNewCredentials(t *testing.T) {
cred := MustGetNewCredentials()
func TestGetNewCredentials(t *testing.T) {
cred, err := GetNewCredentials()
if err != nil {
t.Fatalf("Failed to get a new credential")
}
if !cred.IsValid() {
t.Fatalf("Failed to get new valid credential")
}
@@ -106,7 +109,14 @@ func TestCreateCredentials(t *testing.T) {
}
func TestCredentialsEqual(t *testing.T) {
cred := MustGetNewCredentials()
cred, err := GetNewCredentials()
if err != nil {
t.Fatalf("Failed to get a new credential")
}
cred2, err := GetNewCredentials()
if err != nil {
t.Fatalf("Failed to get a new credential")
}
testCases := []struct {
cred Credentials
ccred Credentials
@@ -119,7 +129,7 @@ func TestCredentialsEqual(t *testing.T) {
// Empty credentials.
{Credentials{}, cred, false},
// Two different credentialss
{cred, MustGetNewCredentials(), false},
{cred, cred2, false},
// Access key is different in credentials to compare.
{cred, Credentials{AccessKey: "myuser", SecretKey: cred.SecretKey}, false},
// Secret key is different in credentials to compare.