...
1
16
17 package tests
18
19 import (
20 "context"
21 "fmt"
22 "net/http"
23 "testing"
24
25 "github.com/jarcoal/httpmock"
26 "github.com/okta/okta-sdk-golang/v2/okta"
27 "github.com/stretchr/testify/assert"
28 "github.com/stretchr/testify/require"
29 )
30
31 func NewClient(ctx context.Context, conf ...okta.ConfigSetter) (context.Context, *okta.Client, error) {
32 return okta.NewClient(ctx, conf...)
33 }
34
35 func MockResponse(responses ...*http.Response) httpmock.Responder {
36 return func(req *http.Request) (*http.Response, error) {
37 httpmock.GetTotalCallCount()
38 info := httpmock.GetCallCountInfo()
39 count := info[req.Method+" "+req.URL.Path]
40
41 if len(responses) >= count {
42 return responses[count-1], nil
43 }
44
45 return nil, fmt.Errorf("no response found for call %v to %s", count, req.URL.Path)
46 }
47 }
48
49 func AssertResponse(t *testing.T, response *okta.Response, requestMethod string, requestPath string) {
50 require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable")
51 assert.Equal(t, requestMethod, response.Response.Request.Method, "did not make a requestMethod request")
52 assert.Equal(t, requestPath, response.Response.Request.URL.Path, "path for request was incorrect")
53 }
54
View as plain text