|
| 1 | +# Okta SDK Testing Guide |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +The Okta SDK now includes functional unit tests that replace the previous skipped tests. These tests use real API calls to validate SDK functionality. |
| 6 | + |
| 7 | +## Environment Setup |
| 8 | + |
| 9 | +Before running the tests, you need to set up your Okta environment: |
| 10 | + |
| 11 | +### Required values |
| 12 | + |
| 13 | +#### Set the values as Environment variables |
| 14 | + |
| 15 | +```bash |
| 16 | +export OKTA_CLIENT_ORGURL="https://your-okta-domain.okta.com" |
| 17 | +export OKTA_CLIENT_TOKEN="your-okta-api-token" |
| 18 | +``` |
| 19 | + |
| 20 | +#### Set the values in ~/.okta/okta.yaml or .okta.yaml |
| 21 | + |
| 22 | +```yaml |
| 23 | +okta: |
| 24 | + client: |
| 25 | + orgUrl: "https://your-okta-domain.okta.com" |
| 26 | + token: "your-okta-api-token" |
| 27 | +``` |
| 28 | +
|
| 29 | +### Getting Your Okta Credentials |
| 30 | +
|
| 31 | +1. **Okta Organization URL**: Your Okta domain (e.g., `https://dev-123456.okta.com`) |
| 32 | +2. **API Token**: Generate an API token in your Okta Admin Console: |
| 33 | + - Go to Security > API > Tokens |
| 34 | + - Click "Create Token" |
| 35 | + - Give it a descriptive name |
| 36 | + - Copy the token value |
| 37 | + |
| 38 | +## Running Tests |
| 39 | + |
| 40 | +### Run User API Tests |
| 41 | +```bash |
| 42 | +# Run all user tests |
| 43 | +go test -v ./okta/test -run Test_okta_UserAPIService |
| 44 | +
|
| 45 | +# Run specific test |
| 46 | +go test -v ./okta/test -run TestUserAPIService_CreateUser |
| 47 | +``` |
| 48 | + |
| 49 | +### Run All Tests |
| 50 | +```bash |
| 51 | +# Run all API tests |
| 52 | +go test -v ./okta/test |
| 53 | +``` |
| 54 | + |
| 55 | +## Test Features |
| 56 | + |
| 57 | +### Automatic Resource Cleanup |
| 58 | +- Tests automatically track and clean up created users |
| 59 | +- No manual cleanup required |
| 60 | +- Resources are cleaned up even if tests fail |
| 61 | + |
| 62 | +### Test Data Management |
| 63 | +- Singleton TestDataManager handles resource lifecycle |
| 64 | +- Automatic tracking of created resources |
| 65 | +- Environment validation before test execution |
| 66 | + |
| 67 | +### Test Helpers |
| 68 | +- Factory methods for creating test data |
| 69 | +- Consistent test user profiles |
| 70 | +- Password and credential generation |
| 71 | + |
| 72 | +## Test Structure |
| 73 | + |
| 74 | +### TestMain Pattern |
| 75 | +Each test file uses TestMain for setup/teardown: |
| 76 | +- Environment validation |
| 77 | +- Resource cleanup |
| 78 | +- Centralized configuration |
| 79 | + |
| 80 | +### Test Data Factory |
| 81 | +The TestFactory provides methods for creating test data: |
| 82 | +- `NewValidTestUserProfile()` - Creates user profiles |
| 83 | +- `NewValidTestUserCredentialsWithPassword()` - Creates credentials |
| 84 | +- `NewTestUserProfileUpdate()` - Creates update data |
| 85 | + |
| 86 | +### Real API Testing |
| 87 | +Tests use actual Okta API calls to: |
| 88 | +- Validate SDK functionality |
| 89 | +- Test against real API responses |
| 90 | +- Ensure compatibility with Okta service |
| 91 | + |
| 92 | +## Example Test |
| 93 | + |
| 94 | +```go |
| 95 | +func TestCreateUser(t *testing.T) { |
| 96 | + // Create test data |
| 97 | + testFactory := &okta.TestFactory{} |
| 98 | + profile := testFactory.NewValidTestUserProfile() |
| 99 | + credentials := testFactory.NewValidTestUserCredentialsWithPassword() |
| 100 | +
|
| 101 | + // Create user via API |
| 102 | + createReq := okta.NewCreateUserRequest(profile) |
| 103 | + createReq.SetCredentials(*credentials) |
| 104 | +
|
| 105 | + resp, httpRes, err := apiClient.UserAPI.CreateUser(testContext). |
| 106 | + Body(*createReq).Activate(false).Execute() |
| 107 | +
|
| 108 | + // Assertions |
| 109 | + require.NoError(t, err) |
| 110 | + assert.Equal(t, 200, httpRes.StatusCode) |
| 111 | + assert.NotNil(t, resp.Id) |
| 112 | +
|
| 113 | + // Automatic cleanup via TestDataManager |
| 114 | +} |
| 115 | +``` |
| 116 | + |
| 117 | +## Security Notes |
| 118 | + |
| 119 | +- Never commit API tokens to the repository |
| 120 | +- Use environment variables for credentials |
| 121 | +- Tests create and delete real resources in your Okta org |
| 122 | +- Run tests in a development/test environment only |
0 commit comments