summaryrefslogtreecommitdiffstats
path: root/pkg/utils
diff options
context:
space:
mode:
authorJesse Duffield <jessedduffield@gmail.com>2019-02-11 21:30:27 +1100
committerJesse Duffield <jessedduffield@gmail.com>2019-02-11 22:39:17 +1100
commitcfe3605e6b29e23db8dca9eedecc58cb13341587 (patch)
treecff98f9663f184e0979a65135dfd6ab7078744a3 /pkg/utils
parent3a607061a2303d9f45d308de652fbebe7300b43c (diff)
use go-errors package to display stacktrace of errors that cause panics
Diffstat (limited to 'pkg/utils')
-rw-r--r--pkg/utils/utils.go3
-rw-r--r--pkg/utils/utils_test.go37
2 files changed, 24 insertions, 16 deletions
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go
index 390f85f70..60985dd0b 100644
--- a/pkg/utils/utils.go
+++ b/pkg/utils/utils.go
@@ -2,7 +2,6 @@ package utils
import (
"encoding/json"
- "errors"
"fmt"
"log"
"os"
@@ -11,6 +10,8 @@ import (
"strings"
"time"
+ "github.com/go-errors/errors"
+
"github.com/fatih/color"
)
diff --git a/pkg/utils/utils_test.go b/pkg/utils/utils_test.go
index f7545f5e9..ee502c1f8 100644
--- a/pkg/utils/utils_test.go
+++ b/pkg/utils/utils_test.go
@@ -1,7 +1,6 @@
package utils
import (
- "errors"
"testing"
"github.com/stretchr/testify/assert"
@@ -233,9 +232,9 @@ func TestGetDisplayStringArrays(t *testing.T) {
// TestRenderDisplayableList is a function.
func TestRenderDisplayableList(t *testing.T) {
type scenario struct {
- input []Displayable
- expectedString string
- expectedError error
+ input []Displayable
+ expectedString string
+ expectedErrorMessage string
}
scenarios := []scenario{
@@ -245,7 +244,7 @@ func TestRenderDisplayableList(t *testing.T) {
Displayable(&myDisplayable{[]string{}}),
},
"\n",
- nil,
+ "",
},
{
[]Displayable{
@@ -253,7 +252,7 @@ func TestRenderDisplayableList(t *testing.T) {
Displayable(&myDisplayable{[]string{"c", "d"}}),
},
"aa b\nc d",
- nil,
+ "",
},
{
[]Displayable{
@@ -261,23 +260,27 @@ func TestRenderDisplayableList(t *testing.T) {
Displayable(&myDisplayable{[]string{"b", "c"}}),
},
"",
- errors.New("Each item must return the same number of strings to display"),
+ "Each item must return the same number of strings to display",
},
}
for _, s := range scenarios {
str, err := renderDisplayableList(s.input)
assert.EqualValues(t, s.expectedString, str)
- assert.EqualValues(t, s.expectedError, err)
+ if s.expectedErrorMessage != "" {
+ assert.EqualError(t, err, s.expectedErrorMessage)
+ } else {
+ assert.NoError(t, err)
+ }
}
}
// TestRenderList is a function.
func TestRenderList(t *testing.T) {
type scenario struct {
- input interface{}
- expectedString string
- expectedError error
+ input interface{}
+ expectedString string
+ expectedErrorMessage string
}
scenarios := []scenario{
@@ -287,7 +290,7 @@ func TestRenderList(t *testing.T) {
{[]string{"c", "d"}},
},
"aa b\nc d",
- nil,
+ "",
},
{
[]*myStruct{
@@ -295,19 +298,23 @@ func TestRenderList(t *testing.T) {
{},
},
"",
- errors.New("item does not implement the Displayable interface"),
+ "item does not implement the Displayable interface",
},
{
&myStruct{},
"",
- errors.New("RenderList given a non-slice type"),
+ "RenderList given a non-slice type",
},
}
for _, s := range scenarios {
str, err := RenderList(s.input)
assert.EqualValues(t, s.expectedString, str)
- assert.EqualValues(t, s.expectedError, err)
+ if s.expectedErrorMessage != "" {
+ assert.EqualError(t, err, s.expectedErrorMessage)
+ } else {
+ assert.NoError(t, err)
+ }
}
}