Skip to content

Commit 0c7ba12

Browse files
committed
remove unused util funcs
1 parent be61e29 commit 0c7ba12

2 files changed

Lines changed: 0 additions & 141 deletions

File tree

internal/pkg/services/postgresflex/utils/utils.go

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"fmt"
66
"slices"
7-
"strings"
87

98
"github.com/stackitcloud/stackit-cli/internal/pkg/errors"
109

@@ -18,12 +17,6 @@ var instanceTypeToReplicas = map[string]int32{
1817
"Replica": 3,
1918
}
2019

21-
type PostgresFlexClient interface {
22-
ListVersions(ctx context.Context, projectId, region string) postgresflex.ApiListVersionsRequest
23-
GetInstance(ctx context.Context, projectId, region, instanceId string) postgresflex.ApiGetInstanceRequest
24-
GetUser(ctx context.Context, projectId, region, instanceId, userId string) postgresflex.ApiGetUserRequest
25-
}
26-
2720
func AvailableInstanceTypes() []string {
2821
instanceTypes := make([]string, len(instanceTypeToReplicas))
2922
i := 0
@@ -37,40 +30,6 @@ func AvailableInstanceTypes() []string {
3730
return instanceTypes
3831
}
3932

40-
func GetInstanceReplicas(instanceType string) (int32, error) {
41-
numReplicas, ok := instanceTypeToReplicas[instanceType]
42-
if !ok {
43-
return 0, fmt.Errorf("invalid instance type: %v", instanceType)
44-
}
45-
return numReplicas, nil
46-
}
47-
48-
func GetInstanceType(numReplicas int32) (string, error) {
49-
for k, v := range instanceTypeToReplicas {
50-
if v == numReplicas {
51-
return k, nil
52-
}
53-
}
54-
return "", fmt.Errorf("invalid number of replicas: %v", numReplicas)
55-
}
56-
57-
func ValidateFlavorId(flavorId string, flavors []postgresflex.ListFlavors) error {
58-
if flavors == nil {
59-
return fmt.Errorf("nil flavors")
60-
}
61-
62-
for _, f := range flavors {
63-
if strings.EqualFold(f.Id, flavorId) {
64-
return nil
65-
}
66-
}
67-
68-
return &errors.DatabaseInvalidFlavorError{
69-
Service: "postgresflex",
70-
Details: fmt.Sprintf("You provided flavor ID '%s', which is invalid.", flavorId),
71-
}
72-
}
73-
7433
func LoadFlavorId(cpu, ram int64, flavors []postgresflex.ListFlavors) (*string, error) {
7534
if flavors == nil {
7635
return nil, fmt.Errorf("nil flavors")

internal/pkg/services/postgresflex/utils/utils_test.go

Lines changed: 0 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -56,60 +56,6 @@ func newAPIMockClient(s mockSettings) postgresflex.DefaultAPI {
5656
}
5757
}
5858

59-
func TestValidateFlavorId(t *testing.T) {
60-
tests := []struct {
61-
description string
62-
flavorId string
63-
flavors []postgresflex.ListFlavors
64-
isValid bool
65-
}{
66-
{
67-
description: "base",
68-
flavorId: "foo",
69-
flavors: []postgresflex.ListFlavors{
70-
{Id: "bar-1"},
71-
{Id: "bar-2"},
72-
{Id: "foo"},
73-
},
74-
isValid: true,
75-
},
76-
{
77-
description: "nil flavors",
78-
flavorId: "foo",
79-
flavors: nil,
80-
isValid: false,
81-
},
82-
{
83-
description: "no flavors",
84-
flavorId: "foo",
85-
flavors: []postgresflex.ListFlavors{},
86-
isValid: false,
87-
},
88-
{
89-
description: "invalid flavor",
90-
flavorId: "foo",
91-
flavors: []postgresflex.ListFlavors{
92-
{Id: "bar-1"},
93-
{Id: "bar-2"},
94-
{Id: "bar-3"},
95-
},
96-
isValid: false,
97-
},
98-
}
99-
100-
for _, tt := range tests {
101-
t.Run(tt.description, func(t *testing.T) {
102-
err := ValidateFlavorId(tt.flavorId, tt.flavors)
103-
if tt.isValid && err != nil {
104-
t.Fatalf("should not have failed: %v", err)
105-
}
106-
if !tt.isValid && err == nil {
107-
t.Fatalf("should have failed")
108-
}
109-
})
110-
}
111-
}
112-
11359
func TestLoadFlavorId(t *testing.T) {
11460
tests := []struct {
11561
description string
@@ -358,49 +304,3 @@ func TestGetUserName(t *testing.T) {
358304
})
359305
}
360306
}
361-
362-
func TestGetInstanceType(t *testing.T) {
363-
tests := []struct {
364-
description string
365-
numReplicas int32
366-
expectedOutput string
367-
isValid bool
368-
}{
369-
{
370-
description: "single",
371-
numReplicas: 1,
372-
expectedOutput: "Single",
373-
isValid: true,
374-
},
375-
{
376-
description: "replica set",
377-
numReplicas: 3,
378-
expectedOutput: "Replica",
379-
isValid: true,
380-
},
381-
{
382-
description: "invalid",
383-
numReplicas: 0,
384-
isValid: false,
385-
},
386-
}
387-
388-
for _, tt := range tests {
389-
t.Run(tt.description, func(t *testing.T) {
390-
output, err := GetInstanceType(tt.numReplicas)
391-
if !tt.isValid {
392-
if err == nil {
393-
t.Fatalf("did not fail on invalid input")
394-
}
395-
return
396-
}
397-
if err != nil {
398-
t.Fatalf("failed on valid input: %v", err)
399-
}
400-
401-
if output != tt.expectedOutput {
402-
t.Fatalf("expected output to be %s, got %s", tt.expectedOutput, output)
403-
}
404-
})
405-
}
406-
}

0 commit comments

Comments
 (0)