Skip to content

Commit e8e208d

Browse files
authored
Bump sdk tests (#542)
1 parent 9f92d03 commit e8e208d

File tree

125 files changed

+13250
-245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

125 files changed

+13250
-245
lines changed

.circleci/config.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ orbs:
1212
jobs:
1313
test-v4:
1414
docker:
15-
- image: cimg/go:1.23.0
15+
- image: cimg/go:1.24.0
16+
resource_class: xlarge
1617
steps:
1718
- checkout
1819
- run: go version
@@ -23,7 +24,7 @@ jobs:
2324

2425
snyk-scan:
2526
docker:
26-
- image: cimg/go:1.23.0
27+
- image: cimg/go:1.24.0
2728
steps:
2829
- checkout
2930
- general-platform-helpers/step-load-dependencies
@@ -34,7 +35,7 @@ jobs:
3435

3536
reversing-labs:
3637
docker:
37-
- image: cimg/go:1.23.0
38+
- image: cimg/go:1.24.0
3839
steps:
3940
- checkout
4041
- run:

.generator/templates/api_test.mustache

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,54 @@ Testing {{classname}}Service
88
*/
99

1010
// Code generated by OpenAPI Generator (https://openapi-generator.tech);
11-
// These test need to be empty because of non native (enum) type our sdk have
12-
package {{packageName}}
11+
12+
package {{packageName}}
13+
14+
import (
15+
"context"
16+
"testing"
17+
18+
{{goImportAlias}} "{{gitHost}}/{{gitUserId}}/{{gitRepoId}}{{#isGoSubmodule}}/{{packageName}}{{/isGoSubmodule}}/{{versionName}}/okta"
19+
"github.com/stretchr/testify/assert"
20+
"github.com/stretchr/testify/require"
21+
)
22+
23+
func Test_{{packageName}}_{{classname}}Service(t *testing.T) {
24+
25+
configuration, err := {{goImportAlias}}.NewConfiguration()
26+
require.Nil(t, err)
27+
apiClient := {{goImportAlias}}.NewAPIClient(configuration)
28+
29+
{{#operations}}
30+
{{#operation}}
31+
t.Run("Test {{classname}}Service {{{nickname}}}", func(t *testing.T) {
32+
33+
{{^pathParams}}
34+
t.Skip("skip test") // remove to run test
35+
{{/pathParams}}
36+
{{#pathParams}}
37+
{{#-first}}
38+
t.Skip("skip test") // remove to run test
39+
40+
{{/-first}}
41+
{{#isPrimitiveType}}
42+
var {{paramName}} {{{dataType}}}
43+
{{/isPrimitiveType}}
44+
{{^isPrimitiveType}}
45+
var {{paramName}} {{goImportAlias}}.{{{dataType}}}
46+
{{/isPrimitiveType}}
47+
{{/pathParams}}
48+
49+
{{#returnType}}resp, {{/returnType}}httpRes, err := apiClient.{{classname}}.{{operationId}}(context.Background(){{#pathParams}}, {{paramName}}{{/pathParams}}).Execute()
50+
51+
require.Nil(t, err)
52+
{{#returnType}}
53+
require.NotNil(t, resp)
54+
{{/returnType}}
55+
assert.Equal(t, 200, httpRes.StatusCode)
56+
57+
})
58+
59+
{{/operation}}
60+
{{/operations}}
61+
}

Makefile

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,24 @@ endif
5656
fmt: check-golangci-lint # Format the code using `golangci-lint`
5757
@$(GOLANGCI_LINT) fmt
5858

59+
.PHONY: import
60+
import: # Run goimports on all Go files
61+
@goimports -w .
62+
5963
check-golangci-lint:
6064
@which $(GOLANGCI_LINT) > /dev/null || curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/HEAD/install.sh | sh -s -- -b $(shell go env GOPATH)/bin $(GOLANGCI_LINT_VERSION)
6165

6266
test:
63-
go test -failfast -race ./okta -test.v
67+
go test -cover -coverpkg=./okta -failfast -race ./okta ./okta/test -test.v
68+
69+
test\:all:
70+
go test -cover -coverpkg=./okta -failfast -race ./okta ./okta/test -test.v
71+
72+
test\:integration:
73+
go test -cover -coverpkg=./okta -failfast -race ./okta/test -test.v
74+
75+
test\:unit:
76+
go test -cover -coverpkg=./okta -failfast -race ./okta -test.v
6477

6578
generate:
6679
npx @openapitools/openapi-generator-cli generate -c ./.generator/config.yaml -i .generator/okta-management-APIs-oasv3-noEnums-inheritance.yaml --skip-validate-spec

TESTING.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
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

Comments
 (0)