forked from cloudhut/connect-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclient_test.go
40 lines (35 loc) · 1.11 KB
/
client_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
package connect
import (
"github.com/jarcoal/httpmock"
"github.com/stretchr/testify/assert"
"net/http"
"strconv"
"testing"
"time"
)
func TestNewClient(t *testing.T) {
hostUrl := "https://kafka-connect.com"
timeOut := 5 * time.Second
c := NewClient(WithHost(hostUrl), WithTimeout(timeOut))
assert.Equal(t, hostUrl, c.hostURL)
assert.Equal(t, timeOut, c.timeout)
}
// newJsonStringResponder creates a Responder from a given body (as a string) and status code and
// sets the JSON content type.
//
// To pass the content of an existing file as body use httpmock.File as in:
// httpmock.NewStringResponder(200, httpmock.File("body.txt").String())
func newJsonStringResponder(status int, body string) httpmock.Responder {
return httpmock.ResponderFromResponse(newJsonStringResponse(status, body))
}
func newJsonStringResponse(status int, body string) *http.Response {
h := http.Header{}
h.Set("Content-Type", "application/json")
return &http.Response{
Status: strconv.Itoa(status),
StatusCode: status,
Body: httpmock.NewRespBodyFromString(body),
Header: h,
ContentLength: -1,
}
}