Skip to content

Commit 7f8b310

Browse files
committed
chore(logme): refactor tests
1 parent b48f589 commit 7f8b310

3 files changed

Lines changed: 21 additions & 16 deletions

File tree

internal/cmd/logme/credentials/create/create_test.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ import (
44
"context"
55
"testing"
66

7-
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
8-
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
9-
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
10-
loadbalancer "github.com/stackitcloud/stackit-sdk-go/services/loadbalancer/v2api"
11-
127
"github.com/google/go-cmp/cmp"
138
"github.com/google/go-cmp/cmp/cmpopts"
149
"github.com/google/uuid"
10+
"github.com/stackitcloud/stackit-cli/internal/pkg/globalflags"
11+
"github.com/stackitcloud/stackit-cli/internal/pkg/testparams"
12+
"github.com/stackitcloud/stackit-cli/internal/pkg/testutils"
1513
logme "github.com/stackitcloud/stackit-sdk-go/services/logme/v2api"
1614
)
1715

@@ -28,9 +26,9 @@ var testRegion = "region"
2826

2927
func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]string {
3028
flagValues := map[string]string{
31-
projectIdFlag: testProjectId,
32-
instanceIdFlag: testInstanceId,
33-
globalflags.RegionFlag: testRegion,
29+
projectIdFlag: testProjectId,
30+
instanceIdFlag: testInstanceId,
31+
regionFlag: testRegion,
3432
}
3533
for _, mod := range mods {
3634
mod(flagValues)
@@ -160,8 +158,7 @@ func TestBuildRequest(t *testing.T) {
160158

161159
diff := cmp.Diff(request, tt.expectedRequest,
162160
cmp.AllowUnexported(tt.expectedRequest),
163-
cmpopts.EquateComparable(testCtx, loadbalancer.DefaultAPIService{}),
164-
cmpopts.IgnoreFields(logme.ApiCreateCredentialsRequest{}, "ApiService"),
161+
cmpopts.EquateComparable(testCtx, logme.ApiCreateCredentialsRequest{}),
165162
)
166163
if diff != "" {
167164
t.Fatalf("Data does not match: %s", diff)

internal/cmd/logme/credentials/delete/delete_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,16 @@ import (
1414
)
1515

1616
var projectIdFlag = globalflags.ProjectIdFlag
17+
var regionFlag = globalflags.RegionFlag
1718

1819
type testCtxKey struct{}
1920

2021
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
21-
var testClient = &logme.APIClient{}
22+
var testClient = &logme.APIClient{DefaultAPI: &logme.DefaultAPIService{}}
2223
var testProjectId = uuid.NewString()
2324
var testInstanceId = uuid.NewString()
2425
var testCredentialsId = uuid.NewString()
26+
var testRegion = "region"
2527

2628
func fixtureArgValues(mods ...func(argValues []string)) []string {
2729
argValues := []string{
@@ -37,6 +39,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st
3739
flagValues := map[string]string{
3840
projectIdFlag: testProjectId,
3941
instanceIdFlag: testInstanceId,
42+
regionFlag: testRegion,
4043
}
4144
for _, mod := range mods {
4245
mod(flagValues)
@@ -48,6 +51,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4851
model := &inputModel{
4952
GlobalFlagModel: &globalflags.GlobalFlagModel{
5053
ProjectId: testProjectId,
54+
Region: testRegion,
5155
Verbosity: globalflags.VerbosityDefault,
5256
},
5357
InstanceId: testInstanceId,
@@ -60,7 +64,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6064
}
6165

6266
func fixtureRequest(mods ...func(request *logme.ApiDeleteCredentialsRequest)) logme.ApiDeleteCredentialsRequest {
63-
request := testClient.DeleteCredentials(testCtx, testProjectId, testInstanceId, testCredentialsId)
67+
request := testClient.DefaultAPI.DeleteCredentials(testCtx, testProjectId, testRegion, testInstanceId, testCredentialsId)
6468
for _, mod := range mods {
6569
mod(&request)
6670
}
@@ -188,7 +192,7 @@ func TestBuildRequest(t *testing.T) {
188192

189193
diff := cmp.Diff(request, tt.expectedRequest,
190194
cmp.AllowUnexported(tt.expectedRequest),
191-
cmpopts.EquateComparable(testCtx),
195+
cmpopts.EquateComparable(testCtx, logme.ApiDeleteCredentialsRequest{}),
192196
)
193197
if diff != "" {
194198
t.Fatalf("Data does not match: %s", diff)

internal/cmd/logme/credentials/describe/describe_test.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,16 @@ import (
1515
)
1616

1717
var projectIdFlag = globalflags.ProjectIdFlag
18+
var regionFlag = globalflags.RegionFlag
1819

1920
type testCtxKey struct{}
2021

2122
var testCtx = context.WithValue(context.Background(), testCtxKey{}, "foo")
22-
var testClient = &logme.APIClient{}
23+
var testClient = &logme.APIClient{DefaultAPI: &logme.DefaultAPIService{}}
2324
var testProjectId = uuid.NewString()
2425
var testInstanceId = uuid.NewString()
2526
var testCredentialsId = uuid.NewString()
27+
var testRegion = "region"
2628

2729
func fixtureArgValues(mods ...func(argValues []string)) []string {
2830
argValues := []string{
@@ -38,6 +40,7 @@ func fixtureFlagValues(mods ...func(flagValues map[string]string)) map[string]st
3840
flagValues := map[string]string{
3941
projectIdFlag: testProjectId,
4042
instanceIdFlag: testInstanceId,
43+
regionFlag: testRegion,
4144
}
4245
for _, mod := range mods {
4346
mod(flagValues)
@@ -49,6 +52,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
4952
model := &inputModel{
5053
GlobalFlagModel: &globalflags.GlobalFlagModel{
5154
ProjectId: testProjectId,
55+
Region: testRegion,
5256
Verbosity: globalflags.VerbosityDefault,
5357
},
5458
InstanceId: testInstanceId,
@@ -61,7 +65,7 @@ func fixtureInputModel(mods ...func(model *inputModel)) *inputModel {
6165
}
6266

6367
func fixtureRequest(mods ...func(request *logme.ApiGetCredentialsRequest)) logme.ApiGetCredentialsRequest {
64-
request := testClient.GetCredentials(testCtx, testProjectId, testInstanceId, testCredentialsId)
68+
request := testClient.DefaultAPI.GetCredentials(testCtx, testProjectId, testRegion, testInstanceId, testCredentialsId)
6569
for _, mod := range mods {
6670
mod(&request)
6771
}
@@ -189,7 +193,7 @@ func TestBuildRequest(t *testing.T) {
189193

190194
diff := cmp.Diff(request, tt.expectedRequest,
191195
cmp.AllowUnexported(tt.expectedRequest),
192-
cmpopts.EquateComparable(testCtx),
196+
cmpopts.EquateComparable(testCtx, logme.ApiGetCredentialsRequest{}),
193197
)
194198
if diff != "" {
195199
t.Fatalf("Data does not match: %s", diff)

0 commit comments

Comments
 (0)