55// compatible open source license.
66//go:build integration
77
8- package ostest
8+ package ostest_test
99
1010import (
1111 "context"
@@ -16,13 +16,14 @@ import (
1616 "github.com/stretchr/testify/require"
1717 "github.com/stretchr/testify/suite"
1818
19+ ostest "github.com/opensearch-project/opensearch-go/v4/internal/test"
1920 "github.com/opensearch-project/opensearch-go/v4/opensearchapi"
2021 "github.com/opensearch-project/opensearch-go/v4/opensearchtransport/testutil"
2122)
2223
2324// TestNewClient demonstrates the enhanced client creation with automatic readiness checks
2425func TestNewClient (t * testing.T ) {
25- client , err := NewClient (t )
26+ client , err := ostest . NewClient (t )
2627 require .NoError (t , err , "Failed to create client" )
2728 require .NotNil (t , client , "Client should not be nil" )
2829
@@ -42,23 +43,23 @@ func TestNewClient(t *testing.T) {
4243
4344// TestConfigFunctions tests the configuration utility functions
4445func TestConfigFunctions (t * testing.T ) {
45- // Test IsSecure function
46- t .Run ("IsSecure" , func (t * testing.T ) {
46+ // Test ostest. IsSecure function
47+ t .Run ("ostest. IsSecure" , func (t * testing.T ) {
4748 // Save original value
4849 original := os .Getenv ("SECURE_INTEGRATION" )
4950 defer os .Setenv ("SECURE_INTEGRATION" , original )
5051
5152 // Test false case
5253 os .Setenv ("SECURE_INTEGRATION" , "false" )
53- assert .False (t , IsSecure ())
54+ assert .False (t , ostest . IsSecure ())
5455
5556 // Test true case
5657 os .Setenv ("SECURE_INTEGRATION" , "true" )
57- assert .True (t , IsSecure ())
58+ assert .True (t , ostest . IsSecure ())
5859
5960 // Test empty case
6061 os .Unsetenv ("SECURE_INTEGRATION" )
61- assert .False (t , IsSecure ())
62+ assert .False (t , ostest . IsSecure ())
6263 })
6364
6465 // Test GetPassword function
@@ -76,31 +77,31 @@ func TestConfigFunctions(t *testing.T) {
7677
7778 // Test default admin password for older versions
7879 os .Setenv ("OPENSEARCH_VERSION" , "2.0.0" )
79- password , err := GetPassword ()
80+ password , err := ostest . GetPassword ()
8081 assert .NoError (t , err )
8182 assert .Equal (t , "admin" , password )
8283
8384 // Test strong password for newer versions
8485 os .Setenv ("OPENSEARCH_VERSION" , "2.12.0" )
85- password , err = GetPassword ()
86+ password , err = ostest . GetPassword ()
8687 assert .NoError (t , err )
8788 assert .Equal (t , "myStrongPassword123!" , password )
8889
8990 // Test latest version
9091 os .Setenv ("OPENSEARCH_VERSION" , "latest" )
91- password , err = GetPassword ()
92+ password , err = ostest . GetPassword ()
9293 assert .NoError (t , err )
9394 assert .Equal (t , "myStrongPassword123!" , password )
9495
9596 // Test empty version
9697 os .Unsetenv ("OPENSEARCH_VERSION" )
97- password , err = GetPassword ()
98+ password , err = ostest . GetPassword ()
9899 assert .NoError (t , err )
99100 assert .Equal (t , "myStrongPassword123!" , password )
100101
101102 // ERROR PATH: Test invalid version format
102103 os .Setenv ("OPENSEARCH_VERSION" , "invalid.version" )
103- _ , err = GetPassword ()
104+ _ , err = ostest . GetPassword ()
104105 assert .Error (t , err , "Should error with invalid version format" )
105106 })
106107
@@ -125,7 +126,7 @@ func TestConfigFunctions(t *testing.T) {
125126
126127 // Test insecure config (should return valid HTTP config)
127128 os .Setenv ("SECURE_INTEGRATION" , "false" )
128- config , err := ClientConfig ()
129+ config , err := ostest . ClientConfig ()
129130 assert .NoError (t , err )
130131 assert .NotNil (t , config )
131132 assert .Equal (t , []string {"http://localhost:9200" }, config .Client .Addresses )
@@ -136,7 +137,7 @@ func TestConfigFunctions(t *testing.T) {
136137 // Test secure config - success case
137138 os .Setenv ("SECURE_INTEGRATION" , "true" )
138139 os .Setenv ("OPENSEARCH_VERSION" , "2.12.0" ) // Valid version
139- config , err = ClientConfig ()
140+ config , err = ostest . ClientConfig ()
140141 assert .NoError (t , err )
141142 if config != nil {
142143 assert .Equal (t , "admin" , config .Client .Username )
@@ -148,29 +149,29 @@ func TestConfigFunctions(t *testing.T) {
148149 // ERROR PATH: Test secure config with invalid version
149150 os .Setenv ("SECURE_INTEGRATION" , "true" )
150151 os .Setenv ("OPENSEARCH_VERSION" , "not.a.version" )
151- config , err = ClientConfig ()
152+ config , err = ostest . ClientConfig ()
152153 assert .Error (t , err , "Should propagate GetPassword error" )
153154 assert .Nil (t , config , "Config should be nil on error" )
154155 })
155156}
156157
157158// TestHelperFunctions tests utility functions with different scenarios
158159func TestHelperFunctions (t * testing.T ) {
159- client , err := NewClient (t )
160+ client , err := ostest . NewClient (t )
160161 require .NoError (t , err )
161162
162- // Test SkipIfBelowVersion - this will not skip since we're running on 3.4.0
163- t .Run ("SkipIfBelowVersion" , func (t * testing.T ) {
163+ // Test ostest. SkipIfBelowVersion - this will not skip since we're running on 3.4.0
164+ t .Run ("ostest. SkipIfBelowVersion" , func (t * testing.T ) {
164165 // This should not skip on current version (3.4.0+)
165- SkipIfBelowVersion (t , client , 2 , 0 , "TestFeature" )
166+ ostest . SkipIfBelowVersion (t , client , 2 , 0 , "TestFeature" )
166167 // If we reach here, the test didn't skip
167168 assert .True (t , true , "Test should continue for supported version" )
168169 })
169170
170171 // Test SkipIfNotSecure
171172 t .Run ("SkipIfNotSecure" , func (t * testing.T ) {
172- if IsSecure () {
173- SkipIfNotSecure (t )
173+ if ostest . IsSecure () {
174+ ostest . SkipIfNotSecure (t )
174175 // If we reach here, it's a secure cluster and test continued
175176 assert .True (t , true , "Test should continue for secure cluster" )
176177 }
@@ -184,27 +185,27 @@ func TestHelperFunctions(t *testing.T) {
184185 require .NoError (t , err )
185186
186187 // This tests the JSON comparison utility
187- CompareRawJSONwithParsedJSON (t , resp , resp .Inspect ().Response )
188+ ostest . CompareRawJSONwithParsedJSON (t , resp , resp .Inspect ().Response )
188189 })
189190
190191 // Test GetVersion function
191192 t .Run ("GetVersion" , func (t * testing.T ) {
192193 // Test successful version retrieval
193- major , minor , patch , err := GetVersion (client , t )
194+ major , minor , patch , err := ostest . GetVersion (t , client )
194195 assert .NoError (t , err , "GetVersion should succeed with valid client" )
195196 assert .True (t , major >= 1 , "Major version should be at least 1" )
196197 assert .True (t , minor >= 0 , "Minor version should be non-negative" )
197198 assert .True (t , patch >= 0 , "Patch version should be non-negative" )
198199
199200 // ERROR PATH: Test GetVersion with nil client
200- _ , _ , _ , err = GetVersion (nil , t )
201+ _ , _ , _ , err = ostest . GetVersion (t , nil )
201202 assert .Error (t , err , "GetVersion should error with nil client" )
202203 })
203204
204205 // Test NewClient function
205206 t .Run ("NewClient" , func (t * testing.T ) {
206207 // Test successful client creation (already done above)
207- client , err := NewClient (t )
208+ client , err := ostest . NewClient (t )
208209 assert .NoError (t , err , "NewClient should succeed in normal conditions" )
209210 assert .NotNil (t , client , "Client should not be nil" )
210211
@@ -229,30 +230,14 @@ func TestHelperFunctions(t *testing.T) {
229230 os .Setenv ("SECURE_INTEGRATION" , "true" )
230231 os .Setenv ("OPENSEARCH_VERSION" , "invalid.format" )
231232
232- _ , err = NewClient (t )
233+ _ , err = ostest . NewClient (t )
233234 assert .Error (t , err , "NewClient should propagate ClientConfig errors" )
234235 })
235-
236- // Test extendedReadinessCheck function
237- t .Run ("extendedReadinessCheck" , func (t * testing.T ) {
238- // Test successful validation (using working client)
239- ctx := context .Background ()
240- err := extendedReadinessCheck (ctx , client )
241- assert .NoError (t , err , "extendedReadinessCheck should succeed with healthy cluster" )
242-
243- // ERROR PATH: Test with cancelled context
244- cancelledCtx , cancel := context .WithCancel (context .Background ())
245- cancel () // Cancel immediately
246-
247- err = extendedReadinessCheck (cancelledCtx , client )
248- assert .Error (t , err , "extendedReadinessCheck should error with cancelled context" )
249- assert .Contains (t , err .Error (), "failed" , "Error should contain descriptive message" )
250- })
251236}
252237
253238// ExampleTestSuite demonstrates using the testify suite pattern
254239type ExampleTestSuite struct {
255- OpenSearchTestSuite
240+ ostest. OpenSearchTestSuite
256241}
257242
258243func (s * ExampleTestSuite ) TestClusterHealthWithSuite () {
@@ -300,7 +285,7 @@ func (s *ExampleTestSuite) TestVersionSkipping() {
300285
301286// Test secure cluster skipping if not secure
302287func (s * ExampleTestSuite ) TestSecureSkipping () {
303- if ! IsSecure () {
288+ if ! ostest . IsSecure () {
304289 s .SkipIfNotSecure ()
305290 // This line should not be reached for insecure clusters
306291 s .T ().Error ("This test should have been skipped for insecure cluster" )
0 commit comments