33// The OpenSearch Contributors require contributions made to
44// this file be licensed under the Apache-2.0 license or a
55// compatible open source license.
6+ //go:build integration
67
78package ostest
89
910import (
1011 "context"
11- "crypto/tls"
1212 "encoding/json"
1313 "fmt"
1414 "io"
15- "net/http"
1615 "os"
1716 "testing"
1817 "time"
@@ -37,7 +36,12 @@ func NewClient(t *testing.T) (*opensearchapi.Client, error) {
3736 if config != nil {
3837 client , err = opensearchapi .NewClient (* config )
3938 } else {
40- client , err = opensearchapi .NewDefaultClient ()
39+ // For insecure integration tests, explicitly use HTTP
40+ client , err = opensearchapi .NewClient (opensearchapi.Config {
41+ Client : opensearch.Config {
42+ Addresses : []string {"http://localhost:9200" },
43+ },
44+ })
4145 }
4246 if err != nil {
4347 return nil , err
@@ -117,59 +121,11 @@ func validateClusterReadiness(ctx context.Context, client *opensearchapi.Client)
117121 return nil
118122}
119123
120- // IsSecure returns true when SECURE_INTEGRATION env is set to true
121- func IsSecure () bool {
122- return os .Getenv ("SECURE_INTEGRATION" ) == "true"
123- }
124-
125- // ClientConfig returns an opensearchapi.Config for secure opensearch
126- func ClientConfig () (* opensearchapi.Config , error ) {
127- if IsSecure () {
128- password , err := GetPassword ()
129- if err != nil {
130- return nil , err
131- }
132-
133- return & opensearchapi.Config {
134- Client : opensearch.Config {
135- Username : "admin" ,
136- Password : password ,
137- Addresses : []string {"https://localhost:9200" },
138- Transport : & http.Transport {
139- TLSClientConfig : & tls.Config {InsecureSkipVerify : true },
140- },
141- },
142- }, nil
143- }
144- //nolint:nilnil // easier to test with nil rather then doing complex error handling for tests
145- return nil , nil
146- }
147-
148- // GetPassword returns the password suited for the opensearch version
149- func GetPassword () (string , error ) {
150- var (
151- major , minor int64
152- err error
153- )
154- password := "admin"
155- version := os .Getenv ("OPENSEARCH_VERSION" )
156-
157- if version != "latest" && version != "" {
158- major , minor , _ , err = opensearch .ParseVersion (version )
159- if err != nil {
160- return "" , err
161- }
162- if version == "latest" || major > 2 || (major == 2 && minor >= 12 ) {
163- password = "myStrongPassword123!"
164- }
165- } else {
166- password = "myStrongPassword123!"
167- }
168- return password , nil
169- }
170-
171124// GetVersion gets cluster info and returns version as int's
172125func GetVersion (client * opensearchapi.Client ) (int64 , int64 , int64 , error ) {
126+ if client == nil {
127+ return 0 , 0 , 0 , fmt .Errorf ("client cannot be nil" )
128+ }
173129 resp , err := client .Info (context .Background (), nil )
174130 if err != nil {
175131 return 0 , 0 , 0 , err
0 commit comments