1/* 2 * Copyright 2018 - Present Okta, Inc. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17package tests 18 19import ( 20 "context" 21 "fmt" 22 "net/http" 23 "testing" 24 25 "github.com/jarcoal/httpmock" 26 "github.com/stretchr/testify/assert" 27 "github.com/stretchr/testify/require" 28 29 "github.com/okta/okta-sdk-golang/v2/okta" 30) 31 32func NewClient(ctx context.Context, conf ...okta.ConfigSetter) (context.Context, *okta.Client, error) { 33 return okta.NewClient(ctx, conf...) 34} 35 36func MockResponse(responses ...*http.Response) httpmock.Responder { 37 return func(req *http.Request) (*http.Response, error) { 38 httpmock.GetTotalCallCount() 39 info := httpmock.GetCallCountInfo() 40 count := info[req.Method+" "+req.URL.Path] 41 42 if len(responses) >= count { 43 return responses[count-1], nil 44 } 45 46 return nil, fmt.Errorf("no response found for call %v to %s", count, req.URL.Path) 47 } 48} 49 50func Assert_response(t *testing.T, response *okta.Response, requestMethod string, requestPath string) { 51 require.IsType(t, &okta.Response{}, response, "did not return `*okta.Response` type as second variable") 52 assert.Equal(t, requestMethod, response.Response.Request.Method, "did not make a requestMethod request") 53 assert.Equal(t, requestPath, response.Response.Request.URL.Path, "path for request was incorrect") 54} 55