Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Your contribution is welcome! Thank you for your interest in contributing to the

## Developer Guide
### Repository structure
The SDK STACKIT service modules are located under `services`, which are automatically generated from the [REST API specs](https://github.com/stackitcloud/stackit-api-specifications), except for the `wait.go` and `wait_test.go` files. Therefore, changes to these modules besides the `wait.go` and `wait_test.go` files will not be accepted. Instead, consider proposing changes to the generation process in the [Generator repository](https://github.com/stackitcloud/stackit-sdk-generator).
The SDK STACKIT service modules are located under `services`. The files located in `services/[service]` are are automatically generated from the [REST API specs](https://github.com/stackitcloud/stackit-api-specifications), whereas the ones located in subfolders (like `wait`) are manually maintained. Therefore, changes to files located in `services/[service]` will not be accepted. Instead, consider proposing changes to the generation process in the [Generator repository](https://github.com/stackitcloud/stackit-sdk-generator).
Comment thread
hcsa73 marked this conversation as resolved.
Outdated

Inside `core` you can find several packages that are used by all service modules, such as `auth`, `config` and `wait`. Examples of usage of the SDK are located under the `examples` folder.

Expand Down
3 changes: 2 additions & 1 deletion examples/waiter/waiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/stackitcloud/stackit-sdk-go/core/utils"
"github.com/stackitcloud/stackit-sdk-go/services/dns"
"github.com/stackitcloud/stackit-sdk-go/services/dns/wait"
Comment thread
vicentepinto98 marked this conversation as resolved.
Outdated
)

func main() {
Expand Down Expand Up @@ -37,7 +38,7 @@ func main() {
}

zoneId := *createZoneResp.Zone.Id
wres, err := dns.CreateZoneWaitHandler(ctx, dnsClient, projectId, zoneId).SetTimeout(15 * time.Minute).WaitWithContext(ctx)
wres, err := wait.CreateZoneWaitHandler(ctx, dnsClient, projectId, zoneId).SetTimeout(15 * time.Minute).WaitWithContext(ctx)
if err != nil {
fmt.Fprintf(os.Stderr, "[DNS API] Waiting for zone update: %v\n", err)
os.Exit(1)
Expand Down
7 changes: 4 additions & 3 deletions services/argus/wait.go → services/argus/wait/wait.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package argus
package wait

import (
"context"
"fmt"

"github.com/stackitcloud/stackit-sdk-go/core/wait"
"github.com/stackitcloud/stackit-sdk-go/services/argus"
)

const (
Expand All @@ -18,8 +19,8 @@ const (

// APIClientInterface Interfaces needed for tests
type APIClientInterface interface {
GetInstanceExecute(ctx context.Context, instanceId, projectId string) (*InstanceResponse, error)
GetScrapeConfigsExecute(ctx context.Context, instanceId, projectId string) (*ScrapeConfigsResponse, error)
GetInstanceExecute(ctx context.Context, instanceId, projectId string) (*argus.InstanceResponse, error)
GetScrapeConfigsExecute(ctx context.Context, instanceId, projectId string) (*argus.ScrapeConfigsResponse, error)
}

// will wait for creation
Expand Down
59 changes: 30 additions & 29 deletions services/argus/wait_test.go → services/argus/wait/wait_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package argus
package wait

import (
"context"
Expand All @@ -9,35 +9,36 @@ import (
"github.com/google/go-cmp/cmp/cmpopts"
oapiError "github.com/stackitcloud/stackit-sdk-go/core/oapierror"
"github.com/stackitcloud/stackit-sdk-go/core/utils"
"github.com/stackitcloud/stackit-sdk-go/services/argus"
)

type apiClientMocked struct {
getFails bool
resourceState *string
jobs []Job
jobs []argus.Job
}

func (a *apiClientMocked) GetInstanceExecute(_ context.Context, _, _ string) (*InstanceResponse, error) {
func (a *apiClientMocked) GetInstanceExecute(_ context.Context, _, _ string) (*argus.InstanceResponse, error) {
if a.getFails {
return nil, &oapiError.GenericOpenAPIError{
StatusCode: 500,
}
}

return &InstanceResponse{
return &argus.InstanceResponse{
Id: utils.Ptr("iid"),
Status: a.resourceState,
}, nil
}

func (a *apiClientMocked) GetScrapeConfigsExecute(_ context.Context, _, _ string) (*ScrapeConfigsResponse, error) {
func (a *apiClientMocked) GetScrapeConfigsExecute(_ context.Context, _, _ string) (*argus.ScrapeConfigsResponse, error) {
if a.getFails {
return nil, &oapiError.GenericOpenAPIError{
StatusCode: 500,
}
}

return &ScrapeConfigsResponse{
return &argus.ScrapeConfigsResponse{
Data: &a.jobs,
}, nil
}
Expand Down Expand Up @@ -87,9 +88,9 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
resourceState: tt.resourceState,
}

var wantRes *InstanceResponse
var wantRes *argus.InstanceResponse
if !tt.getFails {
wantRes = &InstanceResponse{
wantRes = &argus.InstanceResponse{
Id: utils.Ptr("iid"),
Status: tt.resourceState,
}
Expand All @@ -107,7 +108,7 @@ func TestCreateInstanceWaitHandler(t *testing.T) {
if wantRes == nil && gotRes != nil {
t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes)
}
if wantRes != nil && !cmp.Equal(gotRes, wantRes, cmpopts.IgnoreUnexported(NullableString{})) {
if wantRes != nil && !cmp.Equal(gotRes, wantRes, cmpopts.IgnoreUnexported(argus.NullableString{})) {
t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes)
}
})
Expand Down Expand Up @@ -153,9 +154,9 @@ func TestUpdateInstanceWaitHandler(t *testing.T) {
resourceState: tt.resourceState,
}

var wantRes *InstanceResponse
var wantRes *argus.InstanceResponse
if !tt.getFails {
wantRes = &InstanceResponse{
wantRes = &argus.InstanceResponse{
Status: tt.resourceState,
Id: utils.Ptr("iid"),
}
Expand All @@ -173,7 +174,7 @@ func TestUpdateInstanceWaitHandler(t *testing.T) {
if wantRes == nil && gotRes != nil {
t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes)
}
if wantRes != nil && !cmp.Equal(gotRes, wantRes, cmpopts.IgnoreUnexported(NullableString{})) {
if wantRes != nil && !cmp.Equal(gotRes, wantRes, cmpopts.IgnoreUnexported(argus.NullableString{})) {
t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes)
}
})
Expand Down Expand Up @@ -219,9 +220,9 @@ func TestDeleteInstanceWaitHandler(t *testing.T) {
resourceState: tt.resourceState,
}

var wantRes *InstanceResponse
var wantRes *argus.InstanceResponse
if !tt.getFails {
wantRes = &InstanceResponse{
wantRes = &argus.InstanceResponse{
Status: tt.resourceState,
Id: utils.Ptr("iid"),
}
Expand All @@ -239,7 +240,7 @@ func TestDeleteInstanceWaitHandler(t *testing.T) {
if wantRes == nil && gotRes != nil {
t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes)
}
if wantRes != nil && !cmp.Equal(gotRes, wantRes, cmpopts.IgnoreUnexported(NullableString{})) {
if wantRes != nil && !cmp.Equal(gotRes, wantRes, cmpopts.IgnoreUnexported(argus.NullableString{})) {
t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes)
}
})
Expand All @@ -250,25 +251,25 @@ func TestCreateScrapeConfigWaitHandler(t *testing.T) {
tests := []struct {
desc string
getFails bool
jobs []Job
jobs []argus.Job
wantErr bool
}{
{
desc: "create_succeeded",
getFails: false,
jobs: []Job{{JobName: utils.Ptr("job")}, {JobName: utils.Ptr("other-job")}},
jobs: []argus.Job{{JobName: utils.Ptr("job")}, {JobName: utils.Ptr("other-job")}},
wantErr: false,
},
{
desc: "create_failed and timeout",
getFails: false,
jobs: []Job{{JobName: utils.Ptr("other-job")}},
jobs: []argus.Job{{JobName: utils.Ptr("other-job")}},
wantErr: true,
},
{
desc: "get_fails",
getFails: true,
jobs: []Job{},
jobs: []argus.Job{},
wantErr: true,
},
}
Expand All @@ -279,9 +280,9 @@ func TestCreateScrapeConfigWaitHandler(t *testing.T) {
jobs: tt.jobs,
}

var wantRes *ScrapeConfigsResponse
var wantRes *argus.ScrapeConfigsResponse
if !tt.getFails {
wantRes = &ScrapeConfigsResponse{
wantRes = &argus.ScrapeConfigsResponse{
Data: &tt.jobs,
}
} else {
Expand All @@ -298,7 +299,7 @@ func TestCreateScrapeConfigWaitHandler(t *testing.T) {
if wantRes == nil && gotRes != nil {
t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes)
}
if wantRes != nil && !cmp.Equal(gotRes, wantRes, cmpopts.IgnoreUnexported(NullableString{})) {
if wantRes != nil && !cmp.Equal(gotRes, wantRes, cmpopts.IgnoreUnexported(argus.NullableString{})) {
t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes)
}
})
Expand All @@ -309,25 +310,25 @@ func TestDeleteScrapeConfigWaitHandler(t *testing.T) {
tests := []struct {
desc string
getFails bool
jobs []Job
jobs []argus.Job
wantErr bool
}{
{
desc: "delete_succeeded",
getFails: false,
jobs: []Job{{JobName: utils.Ptr("other-job")}},
jobs: []argus.Job{{JobName: utils.Ptr("other-job")}},
wantErr: false,
},
{
desc: "timeout",
getFails: false,
jobs: []Job{{JobName: utils.Ptr("job")}},
jobs: []argus.Job{{JobName: utils.Ptr("job")}},
wantErr: true,
},
{
desc: "get_fails",
getFails: true,
jobs: []Job{},
jobs: []argus.Job{},
wantErr: true,
},
}
Expand All @@ -338,9 +339,9 @@ func TestDeleteScrapeConfigWaitHandler(t *testing.T) {
jobs: tt.jobs,
}

var wantRes *ScrapeConfigsResponse
var wantRes *argus.ScrapeConfigsResponse
if !tt.getFails {
wantRes = &ScrapeConfigsResponse{
wantRes = &argus.ScrapeConfigsResponse{
Data: &tt.jobs,
}
} else {
Expand All @@ -357,7 +358,7 @@ func TestDeleteScrapeConfigWaitHandler(t *testing.T) {
if wantRes == nil && gotRes != nil {
t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes)
}
if wantRes != nil && !cmp.Equal(gotRes, wantRes, cmpopts.IgnoreUnexported(NullableString{})) {
if wantRes != nil && !cmp.Equal(gotRes, wantRes, cmpopts.IgnoreUnexported(argus.NullableString{})) {
t.Fatalf("handler gotRes = %v, want %v", gotRes, wantRes)
}
})
Expand Down
7 changes: 4 additions & 3 deletions services/dns/wait.go → services/dns/wait/wait.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package dns
package wait

import (
"context"
"fmt"

"github.com/stackitcloud/stackit-sdk-go/core/wait"
"github.com/stackitcloud/stackit-sdk-go/services/dns"
)

const (
Expand All @@ -18,8 +19,8 @@ const (

// Interfaces needed for tests
type APIClientInterface interface {
GetZoneExecute(ctx context.Context, projectId, zoneId string) (*ZoneResponse, error)
GetRecordSetExecute(ctx context.Context, projectId, zoneId, rrSetId string) (*RecordSetResponse, error)
GetZoneExecute(ctx context.Context, projectId, zoneId string) (*dns.ZoneResponse, error)
GetRecordSetExecute(ctx context.Context, projectId, zoneId, rrSetId string) (*dns.RecordSetResponse, error)
}

// CreateZoneWaitHandler will wait for creation
Expand Down
Loading