...

Source file src/github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn/arn_test.go

Documentation: github.com/aws/aws-sdk-go-v2/internal/endpoints/awsrulesfn

     1  package awsrulesfn
     2  
     3  import (
     4  	"fmt"
     5  	"reflect"
     6  	"testing"
     7  )
     8  
     9  func TestParseARN(t *testing.T) {
    10  	cases := []struct {
    11  		input  string
    12  		expect *ARN
    13  	}{
    14  		{
    15  			input:  "invalid",
    16  			expect: nil,
    17  		},
    18  		{
    19  			input:  "arn:nope",
    20  			expect: nil,
    21  		},
    22  		{
    23  			input: "arn:aws:ecr:us-west-2:123456789012:repository/foo/bar",
    24  			expect: &ARN{
    25  				Partition:  "aws",
    26  				Service:    "ecr",
    27  				Region:     "us-west-2",
    28  				AccountId:  "123456789012",
    29  				ResourceId: []string{"repository", "foo", "bar"},
    30  			},
    31  		},
    32  		{
    33  			input: "arn:aws:elasticbeanstalk:us-east-1:123456789012:environment/My App/MyEnvironment",
    34  			expect: &ARN{
    35  				Partition:  "aws",
    36  				Service:    "elasticbeanstalk",
    37  				Region:     "us-east-1",
    38  				AccountId:  "123456789012",
    39  				ResourceId: []string{"environment", "My App", "MyEnvironment"},
    40  			},
    41  		},
    42  		{
    43  			input: "arn:aws:iam::123456789012:user/David",
    44  			expect: &ARN{
    45  				Partition:  "aws",
    46  				Service:    "iam",
    47  				Region:     "",
    48  				AccountId:  "123456789012",
    49  				ResourceId: []string{"user", "David"},
    50  			},
    51  		},
    52  		{
    53  			input: "arn:aws:rds:eu-west-1:123456789012:db:mysql-db",
    54  			expect: &ARN{
    55  				Partition:  "aws",
    56  				Service:    "rds",
    57  				Region:     "eu-west-1",
    58  				AccountId:  "123456789012",
    59  				ResourceId: []string{"db", "mysql-db"},
    60  			},
    61  		},
    62  		{
    63  			input: "arn:aws:s3:::my_corporate_bucket/exampleobject.png",
    64  			expect: &ARN{
    65  				Partition:  "aws",
    66  				Service:    "s3",
    67  				Region:     "",
    68  				AccountId:  "",
    69  				ResourceId: []string{"my_corporate_bucket", "exampleobject.png"},
    70  			},
    71  		},
    72  	}
    73  	for _, c := range cases {
    74  		t.Run(c.input, func(t *testing.T) {
    75  			actual := ParseARN(c.input)
    76  			if diff := cmpDiff(c.expect, actual); diff != "" {
    77  				t.Errorf("expect ARN match\n%s", diff)
    78  			}
    79  		})
    80  	}
    81  }
    82  
    83  func cmpDiff(e, a interface{}) string {
    84  	if !reflect.DeepEqual(e, a) {
    85  		return fmt.Sprintf("%v != %v", e, a)
    86  	}
    87  	return ""
    88  }
    89  

View as plain text