github.com/gravitational/teleport/api@v0.0.0-20240507183017-3110591cbafc/utils/aws/region_test.go (about) 1 /* 2 Copyright 2022 Gravitational, Inc. 3 4 Licensed under the Apache License, Version 2.0 (the "License"); 5 you may not use this file except in compliance with the License. 6 You may obtain a copy of the License at 7 8 http://www.apache.org/licenses/LICENSE-2.0 9 10 Unless required by applicable law or agreed to in writing, software 11 distributed under the License is distributed on an "AS IS" BASIS, 12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 See the License for the specific language governing permissions and 14 limitations under the License. 15 */ 16 17 package aws 18 19 import ( 20 "testing" 21 22 "github.com/stretchr/testify/require" 23 ) 24 25 func TestShortRegionToRegion(t *testing.T) { 26 t.Run("valid regions", func(t *testing.T) { 27 t.Parallel() 28 29 validRegionMap := map[string]string{ 30 "use1": "us-east-1", 31 "use2": "us-east-2", 32 "usw1": "us-west-1", 33 "usw2": "us-west-2", 34 "cac1": "ca-central-1", 35 "euw1": "eu-west-1", 36 "euw2": "eu-west-2", 37 "euw3": "eu-west-3", 38 "euc1": "eu-central-1", 39 "eus1": "eu-south-1", 40 "eun1": "eu-north-1", 41 "apse1": "ap-southeast-1", 42 "apse2": "ap-southeast-2", 43 "aps1": "ap-south-1", 44 "apne1": "ap-northeast-1", 45 "apne2": "ap-northeast-2", 46 "ape1": "ap-east-1", 47 "sae1": "sa-east-1", 48 "afs1": "af-south-1", 49 "usgw1": "us-gov-west-1", 50 "usge1": "us-gov-east-1", 51 "cnn1": "cn-north-1", 52 "cnnw1": "cn-northwest-1", 53 } 54 55 for shortRegion, expectRegion := range validRegionMap { 56 actualRegion, ok := ShortRegionToRegion(shortRegion) 57 require.True(t, ok) 58 require.Equal(t, expectRegion, actualRegion) 59 } 60 }) 61 62 invalidTests := []struct { 63 name string 64 input string 65 }{ 66 { 67 name: "invalid prefix", 68 input: "u", 69 }, 70 { 71 name: "not ended in number", 72 input: "use1b", 73 }, 74 { 75 name: "invalid direction", 76 input: "usx1", 77 }, 78 } 79 for _, test := range invalidTests { 80 test := test 81 t.Run(test.name, func(t *testing.T) { 82 t.Parallel() 83 84 _, ok := ShortRegionToRegion(test.input) 85 require.False(t, ok) 86 }) 87 } 88 }