@@ -116,6 +116,10 @@ func getTestFilePath(t *testing.T, suffix string) string {
116
116
}
117
117
118
118
func getTestClient (t * testing.T , testConfig * TestConfig ) (client * scw.Client , cleanup func ()) {
119
+ var err error
120
+ cleanup = func () {}
121
+
122
+ // Init default options
119
123
clientOpts := []scw.ClientOption {
120
124
scw .WithDefaultRegion (scw .RegionFrPar ),
121
125
scw .WithDefaultZone (scw .ZoneFrPar1 ),
@@ -124,39 +128,42 @@ func getTestClient(t *testing.T, testConfig *TestConfig) (client *scw.Client, cl
124
128
scw .WithDefaultOrganizationID ("11111111-1111-1111-1111-111111111111" ),
125
129
}
126
130
127
- if testConfig .DefaultRegion != "" {
128
- clientOpts = append (clientOpts , scw .WithDefaultRegion (testConfig .DefaultRegion ))
129
- }
130
-
131
- if testConfig .DefaultZone != "" {
132
- clientOpts = append (clientOpts , scw .WithDefaultZone (testConfig .DefaultZone ))
133
- }
134
-
131
+ // If client is NOT an E2E client we init http recorder and load configuration.
135
132
if ! testConfig .UseE2EClient {
136
- httpClient , cleanup , err := getHTTPRecoder (t , UpdateCassettes )
133
+ var httpClient * http.Client
134
+ httpClient , cleanup , err = getHTTPRecoder (t , UpdateCassettes )
137
135
require .NoError (t , err )
138
136
clientOpts = append (clientOpts , scw .WithHTTPClient (httpClient ))
137
+
139
138
config , err := scw .LoadConfig ()
140
139
if err == nil {
141
140
p , err := config .GetActiveProfile ()
142
141
require .NoError (t , err )
143
142
clientOpts = append (clientOpts , scw .WithProfile (p ))
144
143
}
144
+ }
145
145
146
- client , err := scw .NewClient (clientOpts ... )
147
- require .NoError (t , err )
148
- return client , cleanup
146
+ // We handle default zone and region configured specifically for a test
147
+ if testConfig .DefaultRegion != "" {
148
+ clientOpts = append (clientOpts , scw .WithDefaultRegion (testConfig .DefaultRegion ))
149
+ }
150
+ if testConfig .DefaultZone != "" {
151
+ clientOpts = append (clientOpts , scw .WithDefaultZone (testConfig .DefaultZone ))
149
152
}
150
153
151
- client , err := scw .NewClient (clientOpts ... )
152
- require .NoError (t , err )
153
- res , err := test .NewAPI (client ).Register (& test.RegisterRequest {Username : "sidi" })
154
+ client , err = scw .NewClient (clientOpts ... )
154
155
require .NoError (t , err )
155
156
156
- client , err = scw .NewClient (append (clientOpts , scw .WithAuth (res .AccessKey , res .SecretKey ))... )
157
- require .NoError (t , err )
157
+ // If client is an E2E client we must register and use returned credential.
158
+ if testConfig .UseE2EClient {
159
+ res , err := test .NewAPI (client ).Register (& test.RegisterRequest {Username : "sidi" })
160
+ require .NoError (t , err )
161
+
162
+ client , err = scw .NewClient (append (clientOpts , scw .WithAuth (res .AccessKey , res .SecretKey ))... )
163
+ require .NoError (t , err )
164
+ }
158
165
159
- return client , func () {}
166
+ return client , cleanup
160
167
}
161
168
162
169
// Run a CLI integration test. See TestConfig for configuration option
0 commit comments