@@ -12,6 +12,7 @@ import (
1212 "github.com/google/uuid"
1313 "github.com/stackitcloud/stackit-cli/internal/pkg/utils"
1414 "github.com/stackitcloud/stackit-sdk-go/core/config"
15+ "github.com/stackitcloud/stackit-sdk-go/core/oapierror"
1516 "github.com/stackitcloud/stackit-sdk-go/services/objectstorage"
1617)
1718
@@ -27,11 +28,23 @@ const (
2728)
2829
2930type objectStorageClientMocked struct {
31+ serviceDisabled bool
32+ getServiceStatusFails bool
3033 listCredentialsGroupsFails bool
3134 listCredentialsGroupsResp * objectstorage.ListCredentialsGroupsResponse
3235 listAccessKeysReq objectstorage.ApiListAccessKeysRequest
3336}
3437
38+ func (m * objectStorageClientMocked ) GetServiceStatusExecute (_ context.Context , _ string ) (* objectstorage.ProjectStatus , error ) {
39+ if m .getServiceStatusFails {
40+ return nil , fmt .Errorf ("could not get service status" )
41+ }
42+ if m .serviceDisabled {
43+ return nil , & oapierror.GenericOpenAPIError {StatusCode : 404 }
44+ }
45+ return & objectstorage.ProjectStatus {}, nil
46+ }
47+
3548func (m * objectStorageClientMocked ) ListCredentialsGroupsExecute (_ context.Context , _ string ) (* objectstorage.ListCredentialsGroupsResponse , error ) {
3649 if m .listCredentialsGroupsFails {
3750 return nil , fmt .Errorf ("could not list credentials groups" )
@@ -43,6 +56,58 @@ func (m *objectStorageClientMocked) ListAccessKeys(_ context.Context, _ string)
4356 return m .listAccessKeysReq
4457}
4558
59+ func TestProjectEnabled (t * testing.T ) {
60+ tests := []struct {
61+ description string
62+ serviceDisabled bool
63+ getProjectFails bool
64+ isValid bool
65+ expectedOutput bool
66+ }{
67+ {
68+ description : "project enabled" ,
69+ isValid : true ,
70+ expectedOutput : true ,
71+ },
72+ {
73+ description : "project disabled (404)" ,
74+ serviceDisabled : true ,
75+ isValid : true ,
76+ expectedOutput : false ,
77+ },
78+ {
79+ description : "get project fails" ,
80+ getProjectFails : true ,
81+ isValid : false ,
82+ },
83+ }
84+
85+ for _ , tt := range tests {
86+ t .Run (tt .description , func (t * testing.T ) {
87+ client := & objectStorageClientMocked {
88+ serviceDisabled : tt .serviceDisabled ,
89+ getServiceStatusFails : tt .getProjectFails ,
90+ }
91+
92+ output , err := ProjectEnabled (context .Background (), client , testProjectId )
93+
94+ if tt .isValid && err != nil {
95+ fmt .Printf ("failed on valid input: %v" , err )
96+ t .Errorf ("failed on valid input" )
97+ }
98+ if ! tt .isValid && err == nil {
99+ t .Errorf ("did not fail on invalid input" )
100+ }
101+ if ! tt .isValid {
102+ return
103+ }
104+ if output != tt .expectedOutput {
105+ t .Errorf ("expected output to be %t, got %t" , tt .expectedOutput , output )
106+ }
107+ })
108+ }
109+ }
110+
46111func TestGetCredentialsGroupName (t * testing.T ) {
47112 tests := []struct {
48113 description string
0 commit comments