Skip to content

Commit

Permalink
Add some more unit tests (#3517)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nils Koch authored Jan 4, 2024
1 parent 7d131d6 commit fce69f0
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 0 deletions.
35 changes: 35 additions & 0 deletions cloudapi/errors_test.go
Original file line number Diff line number Diff line change
@@ -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())
}
26 changes: 26 additions & 0 deletions cloudapi/util_test.go
Original file line number Diff line number Diff line change
@@ -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))
}

0 comments on commit fce69f0

Please sign in to comment.