Skip to content

Commit ddf1e6f

Browse files
author
Anton Bozhiy
committed
add location/region codes to all associated responses, upgrade go-client version, generate hosts_service mocks
1 parent 66cf8a0 commit ddf1e6f

52 files changed

Lines changed: 424 additions & 45 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cmd/base/list_options.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,21 @@ func (o *LocationIDOption[T]) ApplyToCollection(collection serverscom.Collection
120120
}
121121
}
122122

123+
// location code option
124+
type LocationCodeOption[T any] struct {
125+
locationCode string
126+
}
127+
128+
func (o *LocationCodeOption[T]) AddFlags(cmd *cobra.Command) {
129+
cmd.Flags().StringVar(&o.locationCode, "location-code", "", "Filter results by location code")
130+
}
131+
132+
func (o *LocationCodeOption[T]) ApplyToCollection(collection serverscom.Collection[T]) {
133+
if o.locationCode != "" {
134+
collection.SetParam("location_code", o.locationCode)
135+
}
136+
}
137+
123138
// cluster id option
124139
type ClusterIDOption[T any] struct {
125140
clusterID string

cmd/entities/cloud-backups/cloud_backups_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@ var (
2020
fixtureBasePath = filepath.Join("..", "..", "..", "testdata", "entities", "cloud-backups")
2121
fixedTime = time.Date(2025, 1, 1, 12, 0, 0, 0, time.UTC)
2222
fixedTime2 = time.Date(2025, 1, 2, 12, 0, 0, 0, time.UTC)
23+
testRegionCode = "AMS1"
2324
testBackupOpenstackUUID *string
2425
testBackup = serverscom.CloudBlockStorageBackup{
2526
ID: testBackupID,
2627
OpenstackUUID: testBackupOpenstackUUID,
2728
OpenstackVolumeUUID: testVolumeUUID,
2829
RegionID: 1,
30+
RegionCode: testRegionCode,
2931
Size: 1073741824,
3032
Status: "available",
3133
Labels: map[string]string{"env": "test"},
@@ -37,6 +39,7 @@ var (
3739
OpenstackUUID: testBackupOpenstackUUID,
3840
OpenstackVolumeUUID: testVolumeUUID2,
3941
RegionID: 1,
42+
RegionCode: testRegionCode,
4043
Size: 2147483648,
4144
Status: "available",
4245
Labels: map[string]string{"env": "prod"},

cmd/entities/cloud-instances/cloud_instances_test.go

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@ var (
1818
skeletonTemplatePath = filepath.Join("..", "..", "..", "internal", "output", "skeletons", "templates", "cloud-instances")
1919
fixedTime = time.Date(2025, 1, 1, 12, 0, 0, 0, time.UTC)
2020
testCloudInstanceID = "test-instance-id"
21+
testRegionCode = "AMS1"
2122
testCloudInstance = serverscom.CloudComputingInstance{
2223
ID: testCloudInstanceID,
2324
Name: "test-instance",
2425
RegionID: 1,
25-
RegionCode: "AMS1",
26+
RegionCode: testRegionCode,
2627
OpenstackUUID: "uuid-123",
2728
Status: "active",
2829
FlavorID: "flavor-1",
@@ -45,7 +46,7 @@ var (
4546
ID: "test-instance-id2",
4647
Name: "test-instance2",
4748
RegionID: 1,
48-
RegionCode: "AMS1",
49+
RegionCode: testRegionCode,
4950
OpenstackUUID: "uuid-123",
5051
Status: "active",
5152
FlavorID: "flavor-1",
@@ -111,19 +112,6 @@ func TestListCloudInstancesCmd(t *testing.T) {
111112
}, nil)
112113
},
113114
},
114-
{
115-
name: "list cloud instances by region-code",
116-
args: []string{"--region-code", "AMS1"},
117-
output: "json",
118-
expectedOutput: testutils.ReadFixture(filepath.Join(fixtureBasePath, "list.json")),
119-
configureMock: func(mock *mocks.MockCollection[serverscom.CloudComputingInstance]) {
120-
mock.EXPECT().
121-
List(gomock.Any()).
122-
Return([]serverscom.CloudComputingInstance{
123-
testInstance1,
124-
}, nil)
125-
},
126-
},
127115
{
128116
name: "list cloud instances with template",
129117
args: []string{"--template", "{{range .}}Name: {{.Name}}\n{{end}}"},

cmd/entities/cloud-volumes/cloud_volumes_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ var (
1919
fixtureBasePath = filepath.Join("..", "..", "..", "testdata", "entities", "cloud-volumes")
2020
skeletonTemplatePath = filepath.Join("..", "..", "..", "internal", "output", "skeletons", "templates", "cloud-volumes")
2121
fixedTime = time.Date(2025, 1, 1, 12, 0, 0, 0, time.UTC)
22+
testRegionCode = "test"
2223
testVolume = serverscom.CloudBlockStorageVolume{
2324
ID: testVolumeID,
2425
Name: "test-volume",
2526
RegionID: 1,
27+
RegionCode: testRegionCode,
2628
Size: 100,
2729
Description: testutils.PtrString("Test volume"),
2830
Labels: map[string]string{"foo": "bar"},

cmd/entities/hosts/list.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ func newListCmd(cmdContext *base.CmdContext) *cobra.Command {
1717
opts := base.NewListOptions(
1818
&base.BaseListOptions[serverscom.Host]{},
1919
&base.LocationIDOption[serverscom.Host]{},
20+
&base.LocationCodeOption[serverscom.Host]{},
2021
&base.RackIDOption[serverscom.Host]{},
2122
&base.LabelSelectorOption[serverscom.Host]{},
2223
&base.SearchPatternOption[serverscom.Host]{},
@@ -36,6 +37,7 @@ func newListEBMCmd(cmdContext *base.CmdContext) *cobra.Command {
3637
opts := base.NewListOptions(
3738
&base.BaseListOptions[serverscom.DedicatedServer]{},
3839
&base.LocationIDOption[serverscom.DedicatedServer]{},
40+
&base.LocationCodeOption[serverscom.DedicatedServer]{},
3941
&base.RackIDOption[serverscom.DedicatedServer]{},
4042
&base.LabelSelectorOption[serverscom.DedicatedServer]{},
4143
&base.SearchPatternOption[serverscom.DedicatedServer]{},
@@ -55,6 +57,7 @@ func newListKBMCmd(cmdContext *base.CmdContext) *cobra.Command {
5557
opts := base.NewListOptions(
5658
&base.BaseListOptions[serverscom.KubernetesBaremetalNode]{},
5759
&base.LocationIDOption[serverscom.KubernetesBaremetalNode]{},
60+
&base.LocationCodeOption[serverscom.KubernetesBaremetalNode]{},
5861
&base.RackIDOption[serverscom.KubernetesBaremetalNode]{},
5962
&base.LabelSelectorOption[serverscom.KubernetesBaremetalNode]{},
6063
&base.SearchPatternOption[serverscom.KubernetesBaremetalNode]{},
@@ -74,6 +77,7 @@ func newListSBMCmd(cmdContext *base.CmdContext) *cobra.Command {
7477
opts := base.NewListOptions(
7578
&base.BaseListOptions[serverscom.SBMServer]{},
7679
&base.LocationIDOption[serverscom.SBMServer]{},
80+
&base.LocationCodeOption[serverscom.SBMServer]{},
7781
&base.RackIDOption[serverscom.SBMServer]{},
7882
&base.LabelSelectorOption[serverscom.SBMServer]{},
7983
&base.SearchPatternOption[serverscom.SBMServer]{},

cmd/entities/k8s/k8s_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,13 @@ var (
2121
fixtureBasePath = filepath.Join("..", "..", "..", "testdata", "entities", "k8s")
2222
fixedTime = time.Date(2025, 1, 1, 12, 0, 0, 0, time.UTC)
2323
testKubernetesCluster = serverscom.KubernetesCluster{
24-
ID: testId,
25-
Name: "test-cluster",
26-
Status: "active",
27-
LocationID: 1,
28-
Created: fixedTime,
29-
Updated: fixedTime,
24+
ID: testId,
25+
Name: "test-cluster",
26+
Status: "active",
27+
LocationID: 1,
28+
LocationCode: "test-location",
29+
Created: fixedTime,
30+
Updated: fixedTime,
3031
}
3132
testKubernetesClusterNode = serverscom.KubernetesClusterNode{
3233
ID: testNodeId,

cmd/entities/l2_segments/l2_segments_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,13 @@ var (
3636
}
3737

3838
testL2LocationGroup = serverscom.L2LocationGroup{
39-
ID: 10,
40-
Name: testL2SegmentName,
41-
Code: "testCode",
42-
GroupType: "public",
43-
LocationIDs: []int64{1, 2, 3},
44-
Hyperscalers: []string{"AWS", "Azure"},
39+
ID: 10,
40+
Name: testL2SegmentName,
41+
Code: "testCode",
42+
GroupType: "public",
43+
LocationIDs: []int64{1, 2, 3},
44+
LocationCodes: []string{"location1", "location2", "location3"},
45+
Hyperscalers: []string{"AWS", "Azure"},
4546
}
4647

4748
testL2Member = serverscom.L2Member{

cmd/entities/load_balancer_clusters/load_balancer_clusters_test.go

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@ import (
1515
)
1616

1717
var (
18-
testId = "testId"
19-
fixtureBasePath = filepath.Join("..", "..", "..", "testdata", "entities", "lb-clusters")
20-
fixedTime = time.Date(2025, 1, 1, 12, 0, 0, 0, time.UTC)
21-
testLbCluster = serverscom.LoadBalancerCluster{
22-
ID: testId,
23-
Name: "test-lb-cluster",
24-
LocationID: 1,
25-
Status: "active",
26-
Created: fixedTime,
27-
Updated: fixedTime,
18+
testId = "testId"
19+
fixtureBasePath = filepath.Join("..", "..", "..", "testdata", "entities", "lb-clusters")
20+
fixedTime = time.Date(2025, 1, 1, 12, 0, 0, 0, time.UTC)
21+
testLocationCode = "test"
22+
testLbCluster = serverscom.LoadBalancerCluster{
23+
ID: testId,
24+
Name: "test-lb-cluster",
25+
LocationID: 1,
26+
LocationCode: testLocationCode,
27+
Status: "active",
28+
Created: fixedTime,
29+
Updated: fixedTime,
2830
}
2931
)
3032

cmd/entities/load_balancers/load_balancers_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,13 @@ var (
1818
skeletonTemplatePath = filepath.Join("..", "..", "..", "internal", "output", "skeletons", "templates", "lb")
1919
fixedTime = time.Date(2025, 1, 1, 12, 0, 0, 0, time.UTC)
2020
testId = "testId"
21+
testLocationCode = "test"
2122
testLB = serverscom.LoadBalancer{
2223
ID: testId,
2324
Name: "test-l4-lb",
2425
Type: "l4",
2526
LocationID: 1,
27+
LocationCode: testLocationCode,
2628
ExternalAddresses: []string{"127.0.0.1"},
2729
Status: "active",
2830
Labels: map[string]string{"foo": "bar"},
@@ -34,6 +36,7 @@ var (
3436
Name: "test-l4-lb",
3537
Type: "l4",
3638
LocationID: 1,
39+
LocationCode: testLocationCode,
3740
ExternalAddresses: []string{"127.0.0.1"},
3841
Status: "active",
3942
Labels: map[string]string{"foo": "bar"},
@@ -45,6 +48,7 @@ var (
4548
Name: "test-l7-lb",
4649
Type: "l7",
4750
LocationID: 1,
51+
LocationCode: testLocationCode,
4852
ExternalAddresses: []string{"127.0.0.1"},
4953
Domains: []string{"test.com"},
5054
Status: "active",

cmd/entities/network-pools/network_pools_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@ var (
2424
cidr = "192.168.0.0/24"
2525

2626
testNetworkPool = serverscom.NetworkPool{
27-
ID: testID,
28-
Title: &networkTitle,
29-
CIDR: cidr,
30-
Type: "private",
31-
LocationIDs: []int{1, 2},
27+
ID: testID,
28+
Title: &networkTitle,
29+
CIDR: cidr,
30+
Type: "private",
31+
LocationIDs: []int{1, 2},
32+
LocationCodes: []string{"test-location1", "test-location2"},
3233
Labels: map[string]string{
3334
"environment": "testing",
3435
},

0 commit comments

Comments
 (0)