Skip to content

Commit

Permalink
Added test functions for TestNewMethodNotAllowed.
Browse files Browse the repository at this point in the history
Added test functions for methods with additional details and extensions:
- TestNewWithDetail
- TestNewWithExtension
  • Loading branch information
shelleeboo committed Oct 15, 2024
1 parent 93b08ed commit a5729e2
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions problemdetails/problemdetails_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,16 @@ func TestNewNotFound(t *testing.T) {
doCommonAssertions(t, problemDetails)
}

func TestNewMethodNotAllowed(t *testing.T) {
problemDetails := NewMethodNotAllowed()
assert.Equal(t, methodNotAllowed.urn, problemDetails.Type)
assert.Equal(t, methodNotAllowed.code, problemDetails.Status)
assert.Equal(t, methodNotAllowed.title, problemDetails.Title)
assert.Equal(t, "", problemDetails.Detail)
assert.Equal(t, 0, len(problemDetails.Extensions))
doCommonAssertions(t, problemDetails)
}

func TestNewBadRequest(t *testing.T) {
problemDetails := NewBadRequest()
assert.Equal(t, badRequest.urn, problemDetails.Type)
Expand Down Expand Up @@ -107,6 +117,28 @@ func TestNewTooManyRequests(t *testing.T) {
doCommonAssertions(t, problemDetails)
}

func TestNewWithDetail(t *testing.T) {
const detail = "This is a detailed error message"

problemDetails := NewInternalServerError().WithDetail(detail)
assert.Equal(t, internalServerError.urn, problemDetails.Type)
assert.Equal(t, internalServerError.code, problemDetails.Status)
assert.Equal(t, internalServerError.title, problemDetails.Title)

}
func TestNewWithExtension(t *testing.T) {
const key = "example1"
const value = "test"

problemDetails := NewInternalServerError().WithExtension(key, value)
assert.Equal(t, internalServerError.urn, problemDetails.Type)
assert.Equal(t, internalServerError.code, problemDetails.Status)
assert.Equal(t, internalServerError.title, problemDetails.Title)
assert.Equal(t, 1, len(problemDetails.Extensions))
assert.Equal(t, value, problemDetails.Extensions[key])
doCommonAssertions(t, problemDetails)
}

func doCommonAssertions(t *testing.T, problemDetails *ProblemDetails) {
assert.Equal(t, true, strings.Contains(problemDetails.Instance, uuidUrnPrefix))

Expand Down

0 comments on commit a5729e2

Please sign in to comment.