From 3182aa29b65cbc750203285ed0f39110185e9e28 Mon Sep 17 00:00:00 2001 From: "Marcel S. Henselin" Date: Mon, 9 Mar 2026 14:29:29 +0100 Subject: [PATCH] fix: linter errors --- .github/workflows/ci.yaml | 7 + .../postgresflexalpha/flavor/datasource.go | 2 +- .../postgresflexalpha/flavor/functions.go | 2 +- .../flavor/functions_test.go | 267 +++++++++--------- .../flavor/functions_test.go | 2 +- 5 files changed, 144 insertions(+), 136 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 28eb2a51..25f9c1ed 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -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 diff --git a/stackit/internal/services/postgresflexalpha/flavor/datasource.go b/stackit/internal/services/postgresflexalpha/flavor/datasource.go index 69c2a0b8..455baf14 100644 --- a/stackit/internal/services/postgresflexalpha/flavor/datasource.go +++ b/stackit/internal/services/postgresflexalpha/flavor/datasource.go @@ -1,4 +1,4 @@ -package postgresFlexAlphaFlavor +package postgresflexalphaflavor import ( "context" diff --git a/stackit/internal/services/postgresflexalpha/flavor/functions.go b/stackit/internal/services/postgresflexalpha/flavor/functions.go index 948c51ad..97788dc8 100644 --- a/stackit/internal/services/postgresflexalpha/flavor/functions.go +++ b/stackit/internal/services/postgresflexalpha/flavor/functions.go @@ -1,4 +1,4 @@ -package postgresFlexAlphaFlavor +package postgresflexalphaflavor import ( "context" diff --git a/stackit/internal/services/postgresflexalpha/flavor/functions_test.go b/stackit/internal/services/postgresflexalpha/flavor/functions_test.go index b14bd3fd..164f40a7 100644 --- a/stackit/internal/services/postgresflexalpha/flavor/functions_test.go +++ b/stackit/internal/services/postgresflexalpha/flavor/functions_test.go @@ -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)) + } +} +*/ diff --git a/stackit/internal/services/sqlserverflexbeta/flavor/functions_test.go b/stackit/internal/services/sqlserverflexbeta/flavor/functions_test.go index 45998592..72143b7f 100644 --- a/stackit/internal/services/sqlserverflexbeta/flavor/functions_test.go +++ b/stackit/internal/services/sqlserverflexbeta/flavor/functions_test.go @@ -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 {