aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn/partition_test.go
blob: 94930bd84de3f424ca33a0b3bc10512cd580d1c4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package awsrulesfn

import (
	"testing"
)

var mockPartitions = []Partition{
	{
		ID:          "aws",
		RegionRegex: "^(us|eu|ap|sa|ca|me|af)\\-\\w+\\-\\d+$",
		DefaultConfig: PartitionConfig{
			Name:               "aws",
			DnsSuffix:          "amazonaws.com",
			DualStackDnsSuffix: "api.aws",
			SupportsFIPS:       true,
			SupportsDualStack:  true,
		},
		Regions: map[string]RegionOverrides{
			"af-south-1": {
				Name:               nil,
				DnsSuffix:          nil,
				DualStackDnsSuffix: nil,
				SupportsFIPS:       nil,
				SupportsDualStack:  nil,
			},
			"us-west-2": {
				Name:               nil,
				DnsSuffix:          nil,
				DualStackDnsSuffix: nil,
				SupportsFIPS:       nil,
				SupportsDualStack:  nil,
			},
		},
	},
	{
		ID:          "aws-cn",
		RegionRegex: "^cn\\-\\w+\\-\\d+$",
		DefaultConfig: PartitionConfig{
			Name:               "aws-cn",
			DnsSuffix:          "amazonaws.com.cn",
			DualStackDnsSuffix: "api.amazonwebservices.com.cn",
			SupportsFIPS:       true,
			SupportsDualStack:  true,
		},
		Regions: map[string]RegionOverrides{
			"aws-cn-global": {
				Name:               nil,
				DnsSuffix:          nil,
				DualStackDnsSuffix: nil,
				SupportsFIPS:       nil,
				SupportsDualStack:  nil,
			},
			"cn-north-1": {
				Name:               nil,
				DnsSuffix:          nil,
				DualStackDnsSuffix: nil,
				SupportsFIPS:       nil,
				SupportsDualStack:  nil,
			},
			"cn-northwest-1": {
				Name:               nil,
				DnsSuffix:          nil,
				DualStackDnsSuffix: nil,
				SupportsFIPS:       nil,
				SupportsDualStack:  nil,
			},
		},
	},
}

func TestGetPartition(t *testing.T) {
	cases := map[string]struct {
		Region        string
		PartitionName string
	}{
		"test region match aws": {
			Region: "us-west-2", PartitionName: "aws",
		},
		"test region match aws-cn": {
			Region: "aws-cn-global", PartitionName: "aws-cn",
		},
		"test invalid region; default partition": {
			Region: "foo", PartitionName: "aws",
		},
	}

	for n, c := range cases {
		t.Run(n, func(t *testing.T) {

			// monkey patch the partitions data structure
			// thats used by the GetPartition func
			partitions = mockPartitions

			p := GetPartition(c.Region)
			expected := c.PartitionName
			actual := p.Name
			if expected != actual {
				t.Errorf("expected %v, got %v", expected, actual)
			}
		})
	}
}