-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathclientRest_test.go
43 lines (37 loc) · 982 Bytes
/
clientRest_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
41
42
43
package opslevel_test
import (
"fmt"
"net/http"
"testing"
"github.com/go-resty/resty/v2"
ol "github.com/opslevel/opslevel-go/v2025"
"github.com/rocktavious/autopilot/v2023"
)
const testRestClientResponse = `{ "result": "Hello World!" }`
func testRestClientResponseWriter() autopilot.ResponseWriter {
return func(w http.ResponseWriter) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprint(w, testRestClientResponse)
}
}
func ATestRestClient(endpoint string) *resty.Client {
return ol.NewRestClient(ol.SetURL(
autopilot.RegisterEndpoint(
fmt.Sprintf("/%s", endpoint),
testRestClientResponseWriter(),
autopilot.SkipRequestValidation(),
),
),
)
}
func TestRestClientQuery(t *testing.T) {
// Arrange
client := ATestRestClient("rest/example")
resp := &ol.RestResponse{}
// Act
_, err := client.R().SetResult(resp).Get("")
// Assert
autopilot.Ok(t, err)
autopilot.Equals(t, "Hello World!", resp.Result)
}