Skip to content

Commit

Permalink
Update GetRegionFromCountry and GetRegionFromEndpoint to be package m…
Browse files Browse the repository at this point in the history
…ethods
  • Loading branch information
TheoBrigitte committed Dec 2, 2024
1 parent 5b5218e commit a4fdf5d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
2 changes: 1 addition & 1 deletion cmd/order/order.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ func runner(cmd *cobra.Command, args []string) error {
// Prepare item configurations
itemConfigurations := kimsufiorder.NewItemConfigurationsFromMap(itemUserConfigurations)
itemConfigurations.Add(kimsufiorder.ConfigurationLabelDatacenter, datacenter)
r := kimsufiregion.AllowedRegions.GetRegionFromEndpoint(endpoint)
r := kimsufiregion.GetRegionFromEndpoint(endpoint)
if r != nil {
itemConfigurations.Add(kimsufiorder.ConfigurationLabelRegion, r.Region)
}
Expand Down
10 changes: 6 additions & 4 deletions pkg/kimsufi/region/region_methods.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package region

import "strings"
import (
"strings"
)

// GetRegionFromCountry returns the region for a given country code.
func (r Regions) GetRegionFromCountry(country string) *Region {
func GetRegionFromCountry(country string) *Region {
country = strings.ToUpper(country)

for _, region := range r {
for _, region := range AllowedRegions {
for _, c := range region.Countries {
if c.Code == country {
return &region
Expand All @@ -18,7 +20,7 @@ func (r Regions) GetRegionFromCountry(country string) *Region {
}

// GetRegionFromEndpoint returns the region for a given endpoint.
func (r Regions) GetRegionFromEndpoint(endpoint string) *Region {
func GetRegionFromEndpoint(endpoint string) *Region {
for _, region := range AllowedRegions {
if region.Endpoint == endpoint {
return &region
Expand Down
4 changes: 2 additions & 2 deletions pkg/kimsufi/region/region_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestGetRegionFromCountry(t *testing.T) {

for _, tc := range testCases {
t.Run(fmt.Sprintf("%s -> %v", tc.country, tc.expected), func(t *testing.T) {
actual := AllowedRegions.GetRegionFromCountry(tc.country)
actual := GetRegionFromCountry(tc.country)
if tc.expected == nil && actual != nil {
t.Errorf("expected nil, got %v", actual.DisplayName)
} else if tc.expected != nil {
Expand Down Expand Up @@ -81,7 +81,7 @@ func TestGetRegionFromEndpoint(t *testing.T) {

for _, tc := range testCases {
t.Run(fmt.Sprintf("%s -> %v", tc.endpoint, tc.expected), func(t *testing.T) {
actual := AllowedRegions.GetRegionFromEndpoint(tc.endpoint)
actual := GetRegionFromEndpoint(tc.endpoint)
if tc.expected == nil && actual != nil {
t.Errorf("expected nil, got %v", actual.DisplayName)
} else if tc.expected != nil {
Expand Down

0 comments on commit a4fdf5d

Please sign in to comment.