diff --git a/.github/workflows/go-lint.yml b/.github/workflows/go-lint.yml index 4c0f2c6..042340b 100644 --- a/.github/workflows/go-lint.yml +++ b/.github/workflows/go-lint.yml @@ -7,6 +7,7 @@ on: - '**.go' - 'go.mod' - 'go.sum' + - '.golangci.yml' - '.github/workflows/go-lint.yml' pull_request: branches: [ main ] @@ -14,6 +15,7 @@ on: - '**.go' - 'go.mod' - 'go.sum' + - '.golangci.yml' - '.github/workflows/go-lint.yml' jobs: @@ -33,5 +35,5 @@ jobs: - name: Run golangci-lint uses: golangci/golangci-lint-action@v8 with: - version: latest - args: --timeout=5m + version: v2.6.1 + args: --config=.golangci.yml --timeout=5m diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..baa1f31 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,102 @@ +# golangci-lint configuration file +# This ensures consistent linting behavior locally and in CI/CD + +# Defines the configuration version. The only possible value is "2". +version: "2" + +run: + timeout: 5m + tests: true + # Include test files in linting + build-tags: + - integration + +linters: + enable: + # Enabled by default + - errcheck # Check for unchecked errors + - govet # Reports suspicious constructs + - ineffassign # Detect ineffectual assignments + - staticcheck # Advanced Go linter + - unused # Check for unused code + + # Additional recommended linters for SDK quality + - misspell # Find commonly misspelled words + - revive # Fast, configurable linter + - unconvert # Remove unnecessary type conversions + + disable: + # Disabled to avoid noise - can be enabled selectively later + - exhaustruct # Too strict for test structs + - funlen # Function length checks can be too strict + - nlreturn # Newline return can be stylistic + - paralleltest # Not all tests need to be parallel + - wsl # Whitespace linter can be too opinionated + - testifylint # Can be overly strict about testify usage + + # v2 schema exclusions are defined here, not under 'issues' + exclusions: + # Replaces 'issues.exclude-dirs' and 'issues.exclude-files' + paths: + - vendor/ # Exclude the vendor directory + - "pingone/.*\\.go$" # Exclude generated code in pingone directory + + # Replaces 'issues.exclude-rules' + rules: + # Exclude some linters from running on tests files + - path: _test\.go + linters: + - gocyclo + - dupl + - gosec + - goconst + + settings: + errcheck: + check-type-assertions: true + check-blank: false + + govet: + enable-all: true + disable: + - shadow # Can be overly strict + - fieldalignment # Optimization suggestion, not a bug + + staticcheck: + checks: ["all"] + + misspell: + locale: US + + revive: + confidence: 0.8 + rules: + - name: blank-imports + - name: context-as-argument + - name: dot-imports + - name: error-return + - name: error-strings + - name: error-naming + - name: exported + - name: if-return + - name: increment-decrement + - name: var-naming + - name: package-comments + - name: range + - name: receiver-naming + - name: indent-error-flow + - name: superfluous-else + - name: unreachable-code + - name: unused-parameter + +issues: + # Exclude keys moved to 'linters.exclusions' + + # Maximum issues count per one linter + max-issues-per-linter: 0 + + # Maximum count of issues with the same text + max-same-issues: 0 + + # 'exclude-use-default: false' is not present in the v2 schema documentation + # and has been removed. The new default behavior does not use presets. \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 733e2b5..f0d6a35 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -82,21 +82,40 @@ "cSpell.enabled": true, "cSpell.words": [ "apikey", + "bxretail", "davinci", "depscheck", "devcheck", + "dupl", + "errcheck", + "exhaustruct", + "fieldalignment", + "funlen", + "github", + "goconst", + "gocyclo", "golangci", "GOPATH", "gosec", + "govet", + "ineffassign", + "nlreturn", "oauth", "oidc", "openapi", + "paralleltest", "patrickcping", "pingidentity", "pingone", "pkcs", "sarif", - "testframework" + "staticcheck", + "stretchr", + "testacc", + "testframework", + "testifylint", + "unconvert", + "uuid" ], "cSpell.ignoreWords": [ "bool", diff --git a/Makefile b/Makefile index fe1a7b4..ea9a424 100644 --- a/Makefile +++ b/Makefile @@ -26,7 +26,7 @@ test-coverage: # Run linting checks lint: - golangci-lint run + golangci-lint run --config=.golangci.yml # Run security scan security: diff --git a/config/pingone.go b/config/pingone.go index af8ebae..5c321fe 100644 --- a/config/pingone.go +++ b/config/pingone.go @@ -12,10 +12,11 @@ import ( "net/http" "strings" - svcOAuth2 "github.com/pingidentity/pingone-go-client/oauth2" - "github.com/pingidentity/pingone-go-client/oidc/endpoints" "golang.org/x/oauth2" "golang.org/x/oauth2/clientcredentials" + + svcOAuth2 "github.com/pingidentity/pingone-go-client/oauth2" + "github.com/pingidentity/pingone-go-client/oidc/endpoints" ) // Configuration represents the complete configuration for the PingOne Go Client SDK. diff --git a/config/pingone_test.go b/config/pingone_test.go index 68a30fe..d88369b 100644 --- a/config/pingone_test.go +++ b/config/pingone_test.go @@ -7,9 +7,11 @@ import ( "net/http" "testing" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + "github.com/pingidentity/pingone-go-client/config" "github.com/pingidentity/pingone-go-client/oauth2" - "github.com/stretchr/testify/assert" ) func TestNewConfiguration(t *testing.T) { @@ -201,7 +203,8 @@ func TestAuthEndpoints(t *testing.T) { }, expectError: false, validateURLs: func(t *testing.T, endpoints interface{}) { - e := endpoints.(struct{ TokenURL string }) + e, ok := endpoints.(struct{ TokenURL string }) + require.True(t, ok, "endpoints should be of expected type") assert.Contains(t, e.TokenURL, "https://custom.pingone.com") }, }, @@ -212,7 +215,8 @@ func TestAuthEndpoints(t *testing.T) { }, expectError: false, validateURLs: func(t *testing.T, endpoints interface{}) { - e := endpoints.(struct{ TokenURL string }) + e, ok := endpoints.(struct{ TokenURL string }) + require.True(t, ok, "endpoints should be of expected type") assert.Contains(t, e.TokenURL, "https://auth.pingone.com/env-id") }, }, @@ -223,7 +227,8 @@ func TestAuthEndpoints(t *testing.T) { }, expectError: false, validateURLs: func(t *testing.T, endpoints interface{}) { - e := endpoints.(struct{ TokenURL string }) + e, ok := endpoints.(struct{ TokenURL string }) + require.True(t, ok, "endpoints should be of expected type") assert.Contains(t, e.TokenURL, "https://auth.pingone.com/env-id") }, }, diff --git a/oauth2/endpoints/endpoints_test.go b/oauth2/endpoints/endpoints_test.go index 44e9363..608cb13 100644 --- a/oauth2/endpoints/endpoints_test.go +++ b/oauth2/endpoints/endpoints_test.go @@ -5,8 +5,9 @@ package endpoints_test import ( "testing" - "github.com/pingidentity/pingone-go-client/oauth2/endpoints" "github.com/stretchr/testify/assert" + + "github.com/pingidentity/pingone-go-client/oauth2/endpoints" ) func TestPingOneEndpoint(t *testing.T) { diff --git a/oauth2/oauth2_test.go b/oauth2/oauth2_test.go index cd6eeb5..eb6153b 100644 --- a/oauth2/oauth2_test.go +++ b/oauth2/oauth2_test.go @@ -5,8 +5,9 @@ package oauth2_test import ( "testing" - "github.com/pingidentity/pingone-go-client/oauth2" "github.com/stretchr/testify/assert" + + "github.com/pingidentity/pingone-go-client/oauth2" ) func TestGrantTypeConstants(t *testing.T) { diff --git a/oidc/endpoints/endpoints_test.go b/oidc/endpoints/endpoints_test.go index edf0330..501df27 100644 --- a/oidc/endpoints/endpoints_test.go +++ b/oidc/endpoints/endpoints_test.go @@ -5,8 +5,9 @@ package endpoints_test import ( "testing" - "github.com/pingidentity/pingone-go-client/oidc/endpoints" "github.com/stretchr/testify/assert" + + "github.com/pingidentity/pingone-go-client/oidc/endpoints" ) func TestPingOneOIDCEndpoint(t *testing.T) { diff --git a/pingone/test/api_da_vinci_variables_test.go b/pingone/test/api_da_vinci_variables_test.go index e5c5717..e3136da 100644 --- a/pingone/test/api_da_vinci_variables_test.go +++ b/pingone/test/api_da_vinci_variables_test.go @@ -98,7 +98,7 @@ func (s *DaVinciVariablesApiServiceSharedEnvTestSuite) TestDaVinciVariableNeverF davinciVariableID := uuid.New() - resp, httpRes, err := s.ApiClient.DaVinciVariablesApi.GetVariableById(s.T().Context(), s.SharedEnvironmentTestSuite.TestEnvironment.Environment.GetId(), davinciVariableID).Execute() + resp, httpRes, err := s.APIClient.DaVinciVariablesApi.GetVariableById(s.T().Context(), s.SharedEnvironmentTestSuite.TestEnvironment.Environment.GetId(), davinciVariableID).Execute() testframework.CheckNotFound(s.T(), resp, httpRes, err) testframework.CheckPingOneAPIErrorResponse(s.T(), err, pingone.NotFoundError{}, regexp.MustCompile("The requested resource was not found")) } @@ -123,7 +123,7 @@ func (s *DaVinciVariablesApiServiceSharedEnvTestSuite) TestDaVinciVariableFullLi } func (s *DaVinciVariablesApiServiceSharedEnvTestSuite) test_pingone_DaVinciVariablesApiService_Create(t *testing.T, payload pingone.DaVinciVariableCreateRequest) (variableID uuid.UUID) { - resp, httpRes, err := s.ApiClient.DaVinciVariablesApi.CreateVariable(s.T().Context(), s.SharedEnvironmentTestSuite.TestEnvironment.Environment.GetId()).DaVinciVariableCreateRequest(payload).Execute() + resp, httpRes, err := s.APIClient.DaVinciVariablesApi.CreateVariable(s.T().Context(), s.SharedEnvironmentTestSuite.TestEnvironment.Environment.GetId()).DaVinciVariableCreateRequest(payload).Execute() testframework.CheckCreated(t, resp, &pingone.DaVinciVariableResponse{}, httpRes, err) require.NotNil(t, resp.Id) @@ -138,7 +138,7 @@ func (s *DaVinciVariablesApiServiceSharedEnvTestSuite) test_pingone_DaVinciVaria } func (s *DaVinciVariablesApiServiceSharedEnvTestSuite) test_pingone_DaVinciVariablesApiService_Get(t *testing.T, variableID uuid.UUID, payload any) { - resp, httpRes, err := s.ApiClient.DaVinciVariablesApi.GetVariableById(s.T().Context(), s.SharedEnvironmentTestSuite.TestEnvironment.Environment.GetId(), variableID).Execute() + resp, httpRes, err := s.APIClient.DaVinciVariablesApi.GetVariableById(s.T().Context(), s.SharedEnvironmentTestSuite.TestEnvironment.Environment.GetId(), variableID).Execute() testframework.CheckFound(t, resp, &pingone.DaVinciVariableResponse{}, httpRes, err) require.NotNil(t, resp.Id) @@ -160,7 +160,7 @@ func (s *DaVinciVariablesApiServiceSharedEnvTestSuite) test_pingone_DaVinciVaria } func (s *DaVinciVariablesApiServiceSharedEnvTestSuite) test_pingone_DaVinciVariablesApiService_Replace(t *testing.T, variableID uuid.UUID, payload pingone.DaVinciVariableReplaceRequest) { - resp, httpRes, err := s.ApiClient.DaVinciVariablesApi.ReplaceVariableById(s.T().Context(), s.SharedEnvironmentTestSuite.TestEnvironment.Environment.GetId(), variableID).DaVinciVariableReplaceRequest(payload).Execute() + resp, httpRes, err := s.APIClient.DaVinciVariablesApi.ReplaceVariableById(s.T().Context(), s.SharedEnvironmentTestSuite.TestEnvironment.Environment.GetId(), variableID).DaVinciVariableReplaceRequest(payload).Execute() testframework.CheckReplaced(t, resp, &pingone.DaVinciVariableResponse{}, httpRes, err) require.NotNil(t, resp.Id) @@ -174,10 +174,10 @@ func (s *DaVinciVariablesApiServiceSharedEnvTestSuite) test_pingone_DaVinciVaria } func (s *DaVinciVariablesApiServiceSharedEnvTestSuite) test_pingone_DaVinciVariablesApiService_Delete(t *testing.T, variableID uuid.UUID) { - httpRes, err := s.ApiClient.DaVinciVariablesApi.DeleteVariableById(s.T().Context(), s.SharedEnvironmentTestSuite.TestEnvironment.Environment.GetId(), variableID).Execute() + httpRes, err := s.APIClient.DaVinciVariablesApi.DeleteVariableById(s.T().Context(), s.SharedEnvironmentTestSuite.TestEnvironment.Environment.GetId(), variableID).Execute() testframework.CheckDeleted(t, httpRes, err) - resp, httpRes, err := s.ApiClient.DaVinciVariablesApi.GetVariableById(s.T().Context(), s.SharedEnvironmentTestSuite.TestEnvironment.Environment.GetId(), variableID).Execute() + resp, httpRes, err := s.APIClient.DaVinciVariablesApi.GetVariableById(s.T().Context(), s.SharedEnvironmentTestSuite.TestEnvironment.Environment.GetId(), variableID).Execute() testframework.CheckNotFound(t, resp, httpRes, err) } diff --git a/pingone/test/api_environments_test.go b/pingone/test/api_environments_test.go index 18d24db..453371d 100644 --- a/pingone/test/api_environments_test.go +++ b/pingone/test/api_environments_test.go @@ -197,7 +197,7 @@ func (s *EnvironmentsApiServiceTestSuite) TestEnvironmentNeverFound() { environmentID := uuid.New() - resp, httpRes, err := s.ApiClient.EnvironmentsApi.GetEnvironmentById(s.T().Context(), environmentID).Execute() + resp, httpRes, err := s.APIClient.EnvironmentsApi.GetEnvironmentById(s.T().Context(), environmentID).Execute() testframework.CheckNotFound(s.T(), resp, httpRes, err) testframework.CheckPingOneAPIErrorResponse(s.T(), err, pingone.NotFoundError{}, regexp.MustCompile("Unable to find environment")) } @@ -223,7 +223,7 @@ func (s *EnvironmentsApiServiceTestSuite) TestEnvironmentFullLifecycle() { } func (s *EnvironmentsApiServiceTestSuite) test_pingone_EnvironmentsApiService_Create(t *testing.T, payload pingone.EnvironmentCreateRequest) (environmentID uuid.UUID) { - resp, httpRes, err := s.ApiClient.EnvironmentsApi.CreateEnvironment(s.T().Context()).EnvironmentCreateRequest(payload).Execute() + resp, httpRes, err := s.APIClient.EnvironmentsApi.CreateEnvironment(s.T().Context()).EnvironmentCreateRequest(payload).Execute() testframework.CheckCreated(t, resp, &pingone.EnvironmentResponse{}, httpRes, err) require.NotNil(t, resp.Id) @@ -238,7 +238,7 @@ func (s *EnvironmentsApiServiceTestSuite) test_pingone_EnvironmentsApiService_Cr } func (s *EnvironmentsApiServiceTestSuite) test_pingone_EnvironmentsApiService_Get(t *testing.T, environmentID uuid.UUID, payload any) { - resp, httpRes, err := s.ApiClient.EnvironmentsApi.GetEnvironmentById(s.T().Context(), environmentID).Execute() + resp, httpRes, err := s.APIClient.EnvironmentsApi.GetEnvironmentById(s.T().Context(), environmentID).Execute() testframework.CheckFound(t, resp, &pingone.EnvironmentResponse{}, httpRes, err) require.NotNil(t, resp.Id) @@ -260,7 +260,7 @@ func (s *EnvironmentsApiServiceTestSuite) test_pingone_EnvironmentsApiService_Ge } func (s *EnvironmentsApiServiceTestSuite) test_pingone_EnvironmentsApiService_Replace(t *testing.T, environmentID uuid.UUID, payload pingone.EnvironmentReplaceRequest) { - resp, httpRes, err := s.ApiClient.EnvironmentsApi.ReplaceEnvironmentById(s.T().Context(), environmentID).EnvironmentReplaceRequest(payload).Execute() + resp, httpRes, err := s.APIClient.EnvironmentsApi.ReplaceEnvironmentById(s.T().Context(), environmentID).EnvironmentReplaceRequest(payload).Execute() testframework.CheckReplaced(t, resp, &pingone.EnvironmentResponse{}, httpRes, err) require.Equal(t, resp.Id, environmentID) @@ -273,10 +273,10 @@ func (s *EnvironmentsApiServiceTestSuite) test_pingone_EnvironmentsApiService_Re } func (s *EnvironmentsApiServiceTestSuite) test_pingone_EnvironmentsApiService_Delete(t *testing.T, environmentID uuid.UUID) { - httpRes, err := s.ApiClient.EnvironmentsApi.DeleteEnvironmentById(s.T().Context(), environmentID).Execute() + httpRes, err := s.APIClient.EnvironmentsApi.DeleteEnvironmentById(s.T().Context(), environmentID).Execute() testframework.CheckDeleted(t, httpRes, err) - resp, httpRes, err := s.ApiClient.EnvironmentsApi.GetEnvironmentById(s.T().Context(), environmentID).Execute() + resp, httpRes, err := s.APIClient.EnvironmentsApi.GetEnvironmentById(s.T().Context(), environmentID).Execute() testframework.CheckNotFound(t, resp, httpRes, err) } @@ -360,7 +360,7 @@ func (s *EnvironmentsApiServiceModifyTestSuite) TestEnvironmentBillOfMaterialsFu } func (s *EnvironmentsApiServiceModifyTestSuite) test_pingone_EnvironmentBillOfMaterialsApiService_Get(t *testing.T, environmentID uuid.UUID, payload any) { - resp, httpRes, err := s.ApiClient.EnvironmentsApi.GetBillOfMaterialsByEnvironmentId(s.T().Context(), environmentID).Execute() + resp, httpRes, err := s.APIClient.EnvironmentsApi.GetBillOfMaterialsByEnvironmentId(s.T().Context(), environmentID).Execute() testframework.CheckFound(t, resp, &pingone.EnvironmentBillOfMaterials{}, httpRes, err) assert.NotNil(t, resp.Links) @@ -383,7 +383,7 @@ func (s *EnvironmentsApiServiceModifyTestSuite) test_pingone_EnvironmentBillOfMa } func (s *EnvironmentsApiServiceModifyTestSuite) test_pingone_EnvironmentBillOfMaterialsApiService_Replace(t *testing.T, environmentID uuid.UUID, payload pingone.EnvironmentBillOfMaterialsReplaceRequest) { - resp, httpRes, err := s.ApiClient.EnvironmentsApi.ReplaceBillOfMaterialsByEnvironmentId(s.T().Context(), environmentID).EnvironmentBillOfMaterialsReplaceRequest(payload).Execute() + resp, httpRes, err := s.APIClient.EnvironmentsApi.ReplaceBillOfMaterialsByEnvironmentId(s.T().Context(), environmentID).EnvironmentBillOfMaterialsReplaceRequest(payload).Execute() testframework.CheckReplaced(t, resp, &pingone.EnvironmentBillOfMaterials{}, httpRes, err) assert.NotNil(t, resp.Links) diff --git a/testframework/checks.go b/testframework/checks.go index 989232b..2478050 100644 --- a/testframework/checks.go +++ b/testframework/checks.go @@ -74,7 +74,9 @@ func checkAPIFailure(t *testing.T, responseDataObj any, httpResponse *http.Respo assert.Equal(t, expectedStatusCode, httpResponse.StatusCode) } -func CheckPingOneAPIErrorResponse(t *testing.T, httpError error, expectedErrorType any, expectedErrorMessageRegex *regexp.Regexp) { +// CheckPingOneAPIErrorResponse verifies that the error is of the expected type. +// The expectedErrorMessageRegex parameter is currently unused but reserved for future validation. +func CheckPingOneAPIErrorResponse(t *testing.T, httpError error, expectedErrorType any, _ *regexp.Regexp) { require.IsType(t, expectedErrorType, httpError) // assert.NotEmpty(t, errorModel.Id) diff --git a/testframework/environment.go b/testframework/environment.go index d3a9d5c..cf3d586 100644 --- a/testframework/environment.go +++ b/testframework/environment.go @@ -7,6 +7,7 @@ import ( "fmt" "github.com/google/uuid" + "github.com/pingidentity/pingone-go-client/pingone" ) diff --git a/testframework/test_suite_new_environment.go b/testframework/test_suite_new_environment.go index 792a1b2..38013be 100644 --- a/testframework/test_suite_new_environment.go +++ b/testframework/test_suite_new_environment.go @@ -44,7 +44,7 @@ func (s *NewEnvironmentTestSuite) SetupTest() { regionCode := os.Getenv("PINGONE_ENVIRONMENT_REGION") - licenseId, err := uuid.Parse(os.Getenv("PINGONE_LICENSE_ID")) + licenseID, err := uuid.Parse(os.Getenv("PINGONE_LICENSE_ID")) if err != nil { s.FailNow("Failed to parse license ID as a valid UUID (PingOne resource ID)", err) } @@ -53,14 +53,14 @@ func (s *NewEnvironmentTestSuite) SetupTest() { DefaultEnvironmentDefinition( fmt.Sprintf("%s%s%s", s.EnvironmentNamePrefix, randomString(10), s.EnvironmentNameSuffix), regionCode, - licenseId, + licenseID, s.WithBootstrap, ), ) err = testEnvironment.Create( *CreateEnvironment( s.T().Context(), - s.ApiClient, + s.APIClient, )) if err != nil { s.FailNow("Failed to create test environment", err) @@ -69,6 +69,7 @@ func (s *NewEnvironmentTestSuite) SetupTest() { s.TestEnvironment = testEnvironment } +// TearDownTest is called after each test and cleans up the environment created for that test. func (s *NewEnvironmentTestSuite) TearDownTest() { s.PingOneTestSuite.TearDownTest() @@ -76,7 +77,7 @@ func (s *NewEnvironmentTestSuite) TearDownTest() { err := s.TestEnvironment.Delete( *DeleteEnvironment( s.T().Context(), - s.ApiClient, + s.APIClient, ).IfExists()) if err != nil { s.FailNow("Failed to delete test environment", err) @@ -84,6 +85,7 @@ func (s *NewEnvironmentTestSuite) TearDownTest() { } } +// TearDownSuite is called after all tests in the suite have completed. func (s *NewEnvironmentTestSuite) TearDownSuite() { s.PingOneTestSuite.TearDownSuite() } diff --git a/testframework/test_suite_pingone.go b/testframework/test_suite_pingone.go index 744ae46..03e2a47 100644 --- a/testframework/test_suite_pingone.go +++ b/testframework/test_suite_pingone.go @@ -3,8 +3,9 @@ package testframework import ( - "github.com/pingidentity/pingone-go-client/pingone" "github.com/stretchr/testify/suite" + + "github.com/pingidentity/pingone-go-client/pingone" ) // PingOneTestSuite provides a base test suite for PingOne API integration tests. @@ -12,18 +13,18 @@ import ( // automatically set up before tests run and cleaned up afterward. type PingOneTestSuite struct { suite.Suite - // ApiClient is the configured PingOne API client for test operations. - ApiClient *pingone.APIClient + // APIClient is the configured PingOne API client for test operations. + APIClient *pingone.APIClient } // SetupSuite initializes the test suite by creating a configured API client. -// This method is called once before all tests in the suite run. If the ApiClient +// This method is called once before all tests in the suite run. If the APIClient // is not already set, it creates a new test client using the default configuration. // The test suite will fail if client creation fails. func (s *PingOneTestSuite) SetupSuite() { - if s.ApiClient == nil { + if s.APIClient == nil { var err error - s.ApiClient, err = TestClient(nil) + s.APIClient, err = TestClient(nil) if err != nil { s.T().Fatalf("Failed to create API client: %v", err) } @@ -43,5 +44,5 @@ func (s *PingOneTestSuite) TearDownTest() {} // TearDownSuite cleans up the test suite by clearing the API client. // This method is called once after all tests in the suite have completed. func (s *PingOneTestSuite) TearDownSuite() { - s.ApiClient = nil + s.APIClient = nil } diff --git a/testframework/test_suite_shared_environment.go b/testframework/test_suite_shared_environment.go index 134e5dd..0e21ebc 100644 --- a/testframework/test_suite_shared_environment.go +++ b/testframework/test_suite_shared_environment.go @@ -41,7 +41,7 @@ func (s *SharedEnvironmentTestSuite) SetupSuite() { regionCode := os.Getenv("PINGONE_ENVIRONMENT_REGION") - licenseId, err := uuid.Parse(os.Getenv("PINGONE_LICENSE_ID")) + licenseID, err := uuid.Parse(os.Getenv("PINGONE_LICENSE_ID")) if err != nil { s.FailNow("Failed to parse license ID as a valid UUID (PingOne resource ID)", err) } @@ -50,14 +50,14 @@ func (s *SharedEnvironmentTestSuite) SetupSuite() { DefaultEnvironmentDefinition( fmt.Sprintf("%s%s%s", s.EnvironmentNamePrefix, randomString(10), s.EnvironmentNameSuffix), regionCode, - licenseId, + licenseID, s.WithBootstrap, ), ) err = testEnvironment.Create( *CreateEnvironment( s.T().Context(), - s.ApiClient, + s.APIClient, ).IfNotExists()) if err != nil { s.FailNow("Failed to create test environment", err) @@ -66,26 +66,28 @@ func (s *SharedEnvironmentTestSuite) SetupSuite() { s.TestEnvironment = testEnvironment } -// Set up the test with a new environment +// SetupTest prepares the test with the shared environment. func (s *SharedEnvironmentTestSuite) SetupTest() { s.PingOneTestSuite.SetupTest() // TODO: Check environment is still present } +// TearDownTest is called after each test to verify the shared environment. func (s *SharedEnvironmentTestSuite) TearDownTest() { s.PingOneTestSuite.TearDownTest() // TODO: Check environment is still present (does the test force removal of the environment by mistake?) } +// TearDownSuite cleans up the shared environment after all tests have completed. func (s *SharedEnvironmentTestSuite) TearDownSuite() { if s.TestEnvironment != nil { err := s.TestEnvironment.Delete( *DeleteEnvironment( s.T().Context(), - s.ApiClient, + s.APIClient, ).IfExists()) if err != nil { s.FailNow("Failed to delete test environment", err)