github.com/gravitational/teleport/api@v0.0.0-20240507183017-3110591cbafc/utils/aws/partition_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 TestGetPartitionFromRegion(t *testing.T) {
    26  	t.Parallel()
    27  
    28  	tests := []struct {
    29  		region          string
    30  		expectPartition string
    31  	}{
    32  		{
    33  			region:          "cn-north-1",
    34  			expectPartition: "aws-cn",
    35  		},
    36  		{
    37  			region:          "cn-northwest-1",
    38  			expectPartition: "aws-cn",
    39  		},
    40  		{
    41  			region:          "us-gov-east-1",
    42  			expectPartition: "aws-us-gov",
    43  		},
    44  		{
    45  			region:          "us-gov-west-1",
    46  			expectPartition: "aws-us-gov",
    47  		},
    48  		{
    49  			region:          "us-east-1",
    50  			expectPartition: "aws",
    51  		},
    52  		{
    53  			region:          "us-west-1",
    54  			expectPartition: "aws",
    55  		},
    56  		{
    57  			region:          "",
    58  			expectPartition: "aws",
    59  		},
    60  	}
    61  
    62  	for _, test := range tests {
    63  		t.Run(test.region, func(t *testing.T) {
    64  			require.Equal(t, test.expectPartition, GetPartitionFromRegion(test.region))
    65  		})
    66  	}
    67  }