fix: linter errors
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 5s
CI Workflow / Test readiness for publishing provider (pull_request) Has been cancelled
CI Workflow / CI run tests (pull_request) Has been cancelled
CI Workflow / Prepare GO cache (pull_request) Has been cancelled
CI Workflow / CI run build and linting (pull_request) Has been cancelled
CI Workflow / Code coverage report (pull_request) Has been cancelled
Some checks failed
CI Workflow / Check GoReleaser config (pull_request) Successful in 5s
CI Workflow / Test readiness for publishing provider (pull_request) Has been cancelled
CI Workflow / CI run tests (pull_request) Has been cancelled
CI Workflow / Prepare GO cache (pull_request) Has been cancelled
CI Workflow / CI run build and linting (pull_request) Has been cancelled
CI Workflow / Code coverage report (pull_request) Has been cancelled
This commit is contained in:
parent
53f4e4bd49
commit
3182aa29b6
5 changed files with 144 additions and 136 deletions
7
.github/workflows/ci.yaml
vendored
7
.github/workflows/ci.yaml
vendored
|
|
@ -305,6 +305,13 @@ jobs:
|
|||
actions: read # to download code coverage results from "main" job
|
||||
pull-requests: write # write permission needed to comment on PR
|
||||
steps:
|
||||
- name: Install needed tools
|
||||
shell: bash
|
||||
run: |
|
||||
set -e
|
||||
apt-get -y -qq update
|
||||
apt-get -y -qq install sudo
|
||||
|
||||
- name: Check new code coverage
|
||||
uses: fgrosse/go-coverage-report@v1.2.0
|
||||
continue-on-error: true # Add this line to prevent pipeline failures in forks
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package postgresFlexAlphaFlavor
|
||||
package postgresflexalphaflavor
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
package postgresFlexAlphaFlavor
|
||||
package postgresflexalphaflavor
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
|
|
|||
|
|
@ -1,134 +1,135 @@
|
|||
package postgresFlexAlphaFlavor
|
||||
package postgresflexalphaflavor
|
||||
|
||||
//
|
||||
// import (
|
||||
// "context"
|
||||
// "testing"
|
||||
//
|
||||
// postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v3alpha1api"
|
||||
//)
|
||||
//
|
||||
// type mockRequest struct {
|
||||
// executeFunc func() (*postgresflex.GetFlavorsResponse, error)
|
||||
//}
|
||||
//
|
||||
// func (m *mockRequest) Page(_ int32) postgresflex.ApiGetFlavorsRequestRequest { return m }
|
||||
// func (m *mockRequest) Size(_ int32) postgresflex.ApiGetFlavorsRequestRequest { return m }
|
||||
// func (m *mockRequest) Sort(_ postgresflex.FlavorSort) postgresflex.ApiGetFlavorsRequestRequest {
|
||||
// return m
|
||||
//}
|
||||
// func (m *mockRequest) Execute() (*postgresflex.GetFlavorsResponse, error) {
|
||||
// return m.executeFunc()
|
||||
//}
|
||||
//
|
||||
// type mockFlavorsClient struct {
|
||||
// executeRequest func() postgresflex.ApiGetFlavorsRequestRequest
|
||||
//}
|
||||
//
|
||||
// func (m *mockFlavorsClient) GetFlavorsRequest(_ context.Context, _, _ string) postgresflex.ApiGetFlavorsRequestRequest {
|
||||
// return m.executeRequest()
|
||||
//}
|
||||
//
|
||||
// var mockResp = func(page int32) (*postgresflex.GetFlavorsResponse, error) {
|
||||
// if page == 1 {
|
||||
// return &postgresflex.GetFlavorsResponse{
|
||||
// Flavors: []postgresflex.ListFlavors{
|
||||
// {Id: "flavor-1", Description: "first"},
|
||||
// {Id: "flavor-2", Description: "second"},
|
||||
// },
|
||||
// }, nil
|
||||
// }
|
||||
// if page == 2 {
|
||||
// return &postgresflex.GetFlavorsResponse{
|
||||
// Flavors: []postgresflex.ListFlavors{
|
||||
// {Id: "flavor-3", Description: "three"},
|
||||
// },
|
||||
// }, nil
|
||||
// }
|
||||
//
|
||||
// return &postgresflex.GetFlavorsResponse{
|
||||
// Flavors: []postgresflex.ListFlavors{},
|
||||
// }, nil
|
||||
//}
|
||||
//
|
||||
// func TestGetFlavorsByFilter(t *testing.T) {
|
||||
// tests := []struct {
|
||||
// description string
|
||||
// projectId string
|
||||
// region string
|
||||
// mockErr error
|
||||
// filter func(postgresflex.ListFlavors) bool
|
||||
// wantCount int
|
||||
// wantErr bool
|
||||
// }{
|
||||
// {
|
||||
// description: "Success - Get all flavors (2 pages)",
|
||||
// projectId: "pid", region: "reg",
|
||||
// filter: func(_ postgresflex.ListFlavors) bool { return true },
|
||||
// wantCount: 3,
|
||||
// wantErr: false,
|
||||
// },
|
||||
// {
|
||||
// description: "Success - Filter flavors by description",
|
||||
// projectId: "pid", region: "reg",
|
||||
// filter: func(f postgresflex.ListFlavors) bool { return f.Description == "first" },
|
||||
// wantCount: 1,
|
||||
// wantErr: false,
|
||||
// },
|
||||
// {
|
||||
// description: "Error - Missing parameters",
|
||||
// projectId: "", region: "reg",
|
||||
// wantErr: true,
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// for _, tt := range tests {
|
||||
// t.Run(
|
||||
// tt.description, func(t *testing.T) {
|
||||
// var currentPage int32
|
||||
// client := &mockFlavorsClient{
|
||||
// executeRequest: func() postgresflex.ApiGetFlavorsRequestRequest {
|
||||
// return mockRequest{
|
||||
// executeFunc: func() (*postgresflex.GetFlavorsResponse, error) {
|
||||
// currentPage++
|
||||
// return mockResp(currentPage)
|
||||
// },
|
||||
// }
|
||||
// },
|
||||
// }
|
||||
// actual, err := getFlavorsByFilter(context.Background(), client, tt.projectId, tt.region, tt.filter)
|
||||
//
|
||||
// if (err != nil) != tt.wantErr {
|
||||
// t.Errorf("getFlavorsByFilter() error = %v, wantErr %v", err, tt.wantErr)
|
||||
// return
|
||||
// }
|
||||
//
|
||||
// if !tt.wantErr && len(actual) != tt.wantCount {
|
||||
// t.Errorf("getFlavorsByFilter() got %d flavors, want %d", len(actual), tt.wantCount)
|
||||
// }
|
||||
// },
|
||||
// )
|
||||
// }
|
||||
//}
|
||||
//
|
||||
//func TestGetAllFlavors(t *testing.T) {
|
||||
// var currentPage int32
|
||||
// client := &mockFlavorsClient{
|
||||
// executeRequest: func() postgresflex.ApiGetFlavorsRequestRequest {
|
||||
// return mockRequest{
|
||||
// executeFunc: func() (*postgresflex.GetFlavorsResponse, error) {
|
||||
// currentPage++
|
||||
// return mockResp(currentPage)
|
||||
// },
|
||||
// }
|
||||
// },
|
||||
// }
|
||||
//
|
||||
// res, err := getAllFlavors(context.Background(), client, "pid", "reg")
|
||||
// if err != nil {
|
||||
// t.Errorf("getAllFlavors() unexpected error: %v", err)
|
||||
// }
|
||||
// if len(res) != 3 {
|
||||
// t.Errorf("getAllFlavors() expected 3 flavor, got %d", len(res))
|
||||
// }
|
||||
//}
|
||||
/*
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
postgresflex "github.com/stackitcloud/stackit-sdk-go/services/postgresflex/v3alpha1api"
|
||||
)
|
||||
|
||||
type mockRequest struct {
|
||||
executeFunc func() (*postgresflex.GetFlavorsResponse, error)
|
||||
}
|
||||
|
||||
func (m *mockRequest) Page(_ int32) postgresflex.ApiGetFlavorsRequestRequest { return m }
|
||||
func (m *mockRequest) Size(_ int32) postgresflex.ApiGetFlavorsRequestRequest { return m }
|
||||
func (m *mockRequest) Sort(_ postgresflex.FlavorSort) postgresflex.ApiGetFlavorsRequestRequest {
|
||||
return m
|
||||
}
|
||||
func (m *mockRequest) Execute() (*postgresflex.GetFlavorsResponse, error) {
|
||||
return m.executeFunc()
|
||||
}
|
||||
|
||||
type mockFlavorsClient struct {
|
||||
executeRequest func() postgresflex.ApiGetFlavorsRequestRequest
|
||||
}
|
||||
|
||||
func (m *mockFlavorsClient) GetFlavorsRequest(_ context.Context, _, _ string) postgresflex.ApiGetFlavorsRequestRequest {
|
||||
return m.executeRequest()
|
||||
}
|
||||
|
||||
var mockResp = func(page int32) (*postgresflex.GetFlavorsResponse, error) {
|
||||
if page == 1 {
|
||||
return &postgresflex.GetFlavorsResponse{
|
||||
Flavors: []postgresflex.ListFlavors{
|
||||
{Id: "flavor-1", Description: "first"},
|
||||
{Id: "flavor-2", Description: "second"},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
if page == 2 {
|
||||
return &postgresflex.GetFlavorsResponse{
|
||||
Flavors: []postgresflex.ListFlavors{
|
||||
{Id: "flavor-3", Description: "three"},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
|
||||
return &postgresflex.GetFlavorsResponse{
|
||||
Flavors: []postgresflex.ListFlavors{},
|
||||
}, nil
|
||||
}
|
||||
|
||||
func TestGetFlavorsByFilter(t *testing.T) {
|
||||
tests := []struct {
|
||||
description string
|
||||
projectId string
|
||||
region string
|
||||
mockErr error
|
||||
filter func(postgresflex.ListFlavors) bool
|
||||
wantCount int
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
description: "Success - Get all flavors (2 pages)",
|
||||
projectId: "pid", region: "reg",
|
||||
filter: func(_ postgresflex.ListFlavors) bool { return true },
|
||||
wantCount: 3,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
description: "Success - Filter flavors by description",
|
||||
projectId: "pid", region: "reg",
|
||||
filter: func(f postgresflex.ListFlavors) bool { return f.Description == "first" },
|
||||
wantCount: 1,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
description: "Error - Missing parameters",
|
||||
projectId: "", region: "reg",
|
||||
wantErr: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
t.Run(
|
||||
tt.description, func(t *testing.T) {
|
||||
var currentPage int32
|
||||
client := &mockFlavorsClient{
|
||||
executeRequest: func() postgresflex.ApiGetFlavorsRequestRequest {
|
||||
return mockRequest{
|
||||
executeFunc: func() (*postgresflex.GetFlavorsResponse, error) {
|
||||
currentPage++
|
||||
return mockResp(currentPage)
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
actual, err := getFlavorsByFilter(context.Background(), client, tt.projectId, tt.region, tt.filter)
|
||||
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("getFlavorsByFilter() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
|
||||
if !tt.wantErr && len(actual) != tt.wantCount {
|
||||
t.Errorf("getFlavorsByFilter() got %d flavors, want %d", len(actual), tt.wantCount)
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAllFlavors(t *testing.T) {
|
||||
var currentPage int32
|
||||
client := &mockFlavorsClient{
|
||||
executeRequest: func() postgresflex.ApiGetFlavorsRequestRequest {
|
||||
return mockRequest{
|
||||
executeFunc: func() (*postgresflex.GetFlavorsResponse, error) {
|
||||
currentPage++
|
||||
return mockResp(currentPage)
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
res, err := getAllFlavors(context.Background(), client, "pid", "reg")
|
||||
if err != nil {
|
||||
t.Errorf("getAllFlavors() unexpected error: %v", err)
|
||||
}
|
||||
if len(res) != 3 {
|
||||
t.Errorf("getAllFlavors() expected 3 flavor, got %d", len(res))
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ package sqlserverFlexBetaFlavor
|
|||
// }
|
||||
//}
|
||||
//
|
||||
//func TestGetAllFlavors(t *testing.T) {
|
||||
// func TestGetAllFlavors(t *testing.T) {
|
||||
// var currentPage int64
|
||||
// client := &mockFlavorsClient{
|
||||
// executeRequest: func() v3beta1api.ApiGetFlavorsRequestRequest {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue