diff --git a/cloudapi/errors_test.go b/cloudapi/errors_test.go new file mode 100644 index 00000000000..79e2dc0d3c6 --- /dev/null +++ b/cloudapi/errors_test.go @@ -0,0 +1,35 @@ +package cloudapi + +import ( + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestContains(t *testing.T) { + t.Parallel() + + s := []string{"a", "b", "c"} + + assert.False(t, contains(s, "e")) + assert.True(t, contains(s, "b")) +} + +func TestErrorResponse_Error(t *testing.T) { + t.Parallel() + + msg1 := "some message" + msg2 := "some other message" + + errResp := ErrorResponse{ + Message: msg1, + Errors: []string{msg2}, + FieldErrors: map[string][]string{ + "field1": {"error1", "error2"}, + }, + Code: 123, + } + + expected := "(E123) " + msg1 + "\n " + msg2 + "\n field1: error1, error2" + assert.Equal(t, expected, errResp.Error()) +} diff --git a/cloudapi/util_test.go b/cloudapi/util_test.go new file mode 100644 index 00000000000..cef495f0e31 --- /dev/null +++ b/cloudapi/util_test.go @@ -0,0 +1,26 @@ +package cloudapi + +import ( + "fmt" + "testing" + + "github.com/stretchr/testify/require" + "gopkg.in/guregu/null.v3" +) + +func TestURLForResults(t *testing.T) { + t.Parallel() + + webAppURL := "http://example.com" + testRunDetails := "http://example-new.com" + refID := "1234" + + conf := Config{ + WebAppURL: null.NewString(webAppURL, true), + } + + expected := fmt.Sprintf("%s/runs/%s", webAppURL, refID) + require.Equal(t, expected, URLForResults(refID, conf)) + conf.TestRunDetails = null.NewString(testRunDetails, true) + require.Equal(t, testRunDetails, URLForResults(refID, conf)) +}