Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
kkumar-gcc committed Nov 2, 2024
1 parent 23c15cf commit b26d506
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
2 changes: 1 addition & 1 deletion contracts/testing/test_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ type TestRequest interface {
Put(uri string, body io.Reader) (TestResponse, error)
Patch(uri string, body io.Reader) (TestResponse, error)
Delete(uri string, body io.Reader) (TestResponse, error)
Head(uri string, body io.Reader) (TestResponse, error)
Head(uri string) (TestResponse, error)
Options(uri string) (TestResponse, error)
}
8 changes: 4 additions & 4 deletions testing/assertable_json_string.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@ type AssertableJSONString struct {
decoded map[string]any
}

func NewAssertableJSONString(jsonAble string) (contractstesting.AssertableJSON, error) {
var decoded = make(map[string]any)
err := json.Unmarshal([]byte(jsonAble), &decoded)
func NewAssertableJSONString(jsonStr string) (contractstesting.AssertableJSON, error) {
var decoded map[string]any
err := json.Unmarshal([]byte(jsonStr), &decoded)
if err != nil {
return nil, err
}

return &AssertableJSONString{
json: jsonAble,
json: jsonStr,
decoded: decoded,
}, nil
}
Expand Down
4 changes: 2 additions & 2 deletions testing/test_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ func (r *TestRequest) Delete(uri string, body io.Reader) (contractstesting.TestR
return r.call(http.MethodDelete, uri, body)
}

func (r *TestRequest) Head(uri string, body io.Reader) (contractstesting.TestResponse, error) {
return r.call(http.MethodHead, uri, body)
func (r *TestRequest) Head(uri string) (contractstesting.TestResponse, error) {
return r.call(http.MethodHead, uri, nil)
}

func (r *TestRequest) Options(uri string) (contractstesting.TestResponse, error) {
Expand Down
5 changes: 5 additions & 0 deletions testing/test_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"net/http"
"strings"
"sync"
"testing"
"time"

Expand All @@ -17,6 +18,7 @@ import (

type TestResponseImpl struct {
t *testing.T
mu sync.Mutex
response *http.Response
content string
}
Expand Down Expand Up @@ -310,6 +312,9 @@ func (r *TestResponseImpl) getStatusCode() int {
}

func (r *TestResponseImpl) getContent() (string, error) {
r.mu.Lock()
defer r.mu.Unlock()

if r.content != "" {
return r.content, nil
}
Expand Down

0 comments on commit b26d506

Please sign in to comment.