...

Source file src/github.com/okta/okta-sdk-golang/v2/tests/unit/session_test.go

Documentation: github.com/okta/okta-sdk-golang/v2/tests/unit

     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  
    17  package unit
    18  
    19  import (
    20  	"context"
    21  	"testing"
    22  
    23  	"github.com/stretchr/testify/require"
    24  
    25  	"github.com/okta/okta-sdk-golang/v2/okta"
    26  
    27  	"github.com/jarcoal/httpmock"
    28  	"github.com/okta/okta-sdk-golang/v2/tests"
    29  )
    30  
    31  func Test_Create_Session(t *testing.T) {
    32  	httpmock.Activate()
    33  	defer httpmock.DeactivateAndReset()
    34  
    35  	ctx, client, err := tests.NewClient(context.TODO(), okta.WithCache(false))
    36  	require.NoError(t, err, "failed to create client")
    37  
    38  	httpmock.RegisterResponder("POST", "/api/v1/sessions",
    39  		tests.MockResponse(
    40  			tests.MockSessionCreateResponse(),
    41  		),
    42  	)
    43  
    44  	csr := okta.CreateSessionRequest{
    45  		SessionToken: "abc123",
    46  	}
    47  
    48  	_, resp, err := client.Session.CreateSession(ctx, csr)
    49  	require.Nil(t, err, "Error should have been nil")
    50  	require.NotNil(t, resp, "Response was nil")
    51  
    52  	httpmock.GetTotalCallCount()
    53  	info := httpmock.GetCallCountInfo()
    54  	require.Equal(t, 1, info["POST /api/v1/sessions"], "did not make exactly 1 call to /api/v1/sessions")
    55  }
    56  

View as plain text