@@ -7,24 +7,27 @@ import (
77 "github.com/google/go-cmp/cmp"
88 "github.com/google/go-cmp/cmp/cmpopts"
99 "github.com/google/uuid"
10- "github.com/stackitcloud/stackit-sdk-go/services/opensearch"
10+ opensearch "github.com/stackitcloud/stackit-sdk-go/services/opensearch/v2api "
1111
1212 "github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
1313 "github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
1414 "github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
15- "github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1615)
1716
1817type testCtxKey struct {}
1918
20- var testCtx = context .WithValue (context .Background (), testCtxKey {}, "foo" )
21- var testClient = & opensearch.APIClient {}
22- var testProjectId = uuid .NewString ()
23- var testInstanceId = uuid .NewString ()
19+ var (
20+ testCtx = context .WithValue (context .Background (), testCtxKey {}, "foo" )
21+ testClient = & opensearch.APIClient {DefaultAPI : & opensearch.DefaultAPIService {}}
22+ testProjectId = uuid .NewString ()
23+ testRegion = "eu01"
24+ testInstanceId = uuid .NewString ()
25+ )
2426
2527func fixtureFlagValues (mods ... func (flagValues map [string ]string )) map [string ]string {
2628 flagValues := map [string ]string {
2729 globalflags .ProjectIdFlag : testProjectId ,
30+ globalflags .RegionFlag : testRegion ,
2831 instanceIdFlag : testInstanceId ,
2932 }
3033 for _ , mod := range mods {
@@ -37,6 +40,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
3740 model := & inputModel {
3841 GlobalFlagModel : & globalflags.GlobalFlagModel {
3942 ProjectId : testProjectId ,
43+ Region : testRegion ,
4044 Verbosity : globalflags .VerbosityDefault ,
4145 },
4246 InstanceId : testInstanceId ,
@@ -48,7 +52,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4852}
4953
5054func fixtureRequest (mods ... func (request * opensearch.ApiCreateCredentialsRequest )) opensearch.ApiCreateCredentialsRequest {
51- request := testClient .CreateCredentials (testCtx , testProjectId , testInstanceId )
55+ request := testClient .DefaultAPI . CreateCredentials (testCtx , testProjectId , testRegion , testInstanceId )
5256 for _ , mod := range mods {
5357 mod (& request )
5458 }
@@ -154,7 +158,7 @@ func TestBuildRequest(t *testing.T) {
154158
155159 diff := cmp .Diff (request , tt .expectedRequest ,
156160 cmp .AllowUnexported (tt .expectedRequest ),
157- cmpopts .EquateComparable (testCtx ),
161+ cmpopts .EquateComparable (testCtx , opensearch. DefaultAPIService {} ),
158162 )
159163 if diff != "" {
160164 t .Fatalf ("Data does not match: %s" , diff )
@@ -181,41 +185,18 @@ func TestOutputResult(t *testing.T) {
181185 wantErr : true ,
182186 },
183187 {
184- name : "set no raw in response" ,
185- args : args {
186- resp : & opensearch.CredentialsResponse {
187- Uri : utils .Ptr ("https://opensearch.example.com" ),
188- },
189- },
190- wantErr : true ,
191- },
192- {
193- name : "set empty raw in response" ,
194- args : args {
195- resp : & opensearch.CredentialsResponse {
196- Raw : & opensearch.RawCredentials {},
197- Uri : utils .Ptr ("https://opensearch.example.com" ),
198- },
199- },
200- wantErr : true ,
201- },
202- {
203- name : "set raw but no uri in response" ,
188+ name : "set uri but no raw in response" ,
204189 args : args {
205190 resp : & opensearch.CredentialsResponse {
206- Raw : & opensearch.RawCredentials {
207- Credentials : & opensearch.Credentials {},
208- },
191+ Uri : "https://opensearch.example.com" ,
209192 },
210193 },
211194 wantErr : true ,
212195 },
213196 {
214- name : "set uri but no raw in response " ,
197+ name : "empty response should not cause panic when password should be hidden " ,
215198 args : args {
216- resp : & opensearch.CredentialsResponse {
217- Uri : utils .Ptr ("https://opensearch.example.com" ),
218- },
199+ showPassword : false ,
219200 },
220201 wantErr : true ,
221202 },
@@ -224,9 +205,9 @@ func TestOutputResult(t *testing.T) {
224205 args : args {
225206 resp : & opensearch.CredentialsResponse {
226207 Raw : & opensearch.RawCredentials {
227- Credentials : & opensearch.Credentials {},
208+ Credentials : opensearch.Credentials {},
228209 },
229- Uri : utils . Ptr ( "https://opensearch.example.com" ) ,
210+ Uri : "https://opensearch.example.com" ,
230211 },
231212 },
232213 wantErr : false ,
0 commit comments