aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn/arn_test.go
blob: bab7f8611004998e545d0976b9a2d6c9d96e2b04 (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
package awsrulesfn

import (
	"github.com/google/go-cmp/cmp"
	"testing"
)

func TestParseARN(t *testing.T) {
	cases := []struct {
		input  string
		expect *ARN
	}{
		{
			input:  "invalid",
			expect: nil,
		},
		{
			input:  "arn:nope",
			expect: nil,
		},
		{
			input: "arn:aws:ecr:us-west-2:123456789012:repository/foo/bar",
			expect: &ARN{
				Partition:  "aws",
				Service:    "ecr",
				Region:     "us-west-2",
				AccountId:  "123456789012",
				ResourceId: []string{"repository", "foo", "bar"},
			},
		},
		{
			input: "arn:aws:elasticbeanstalk:us-east-1:123456789012:environment/My App/MyEnvironment",
			expect: &ARN{
				Partition:  "aws",
				Service:    "elasticbeanstalk",
				Region:     "us-east-1",
				AccountId:  "123456789012",
				ResourceId: []string{"environment", "My App", "MyEnvironment"},
			},
		},
		{
			input: "arn:aws:iam::123456789012:user/David",
			expect: &ARN{
				Partition:  "aws",
				Service:    "iam",
				Region:     "",
				AccountId:  "123456789012",
				ResourceId: []string{"user", "David"},
			},
		},
		{
			input: "arn:aws:rds:eu-west-1:123456789012:db:mysql-db",
			expect: &ARN{
				Partition:  "aws",
				Service:    "rds",
				Region:     "eu-west-1",
				AccountId:  "123456789012",
				ResourceId: []string{"db", "mysql-db"},
			},
		},
		{
			input: "arn:aws:s3:::my_corporate_bucket/exampleobject.png",
			expect: &ARN{
				Partition:  "aws",
				Service:    "s3",
				Region:     "",
				AccountId:  "",
				ResourceId: []string{"my_corporate_bucket", "exampleobject.png"},
			},
		},
	}
	for _, c := range cases {
		t.Run(c.input, func(t *testing.T) {
			actual := ParseARN(c.input)
			if diff := cmp.Diff(c.expect, actual); diff != "" {
				t.Errorf("expect ARN match\n%s", diff)
			}
		})
	}
}