github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/internal/config/lambda/event/arn_test.go (about) 1 // Copyright (c) 2015-2023 MinIO, Inc. 2 // 3 // This file is part of MinIO Object Storage stack 4 // 5 // This program is free software: you can redistribute it and/or modify 6 // it under the terms of the GNU Affero General Public License as published by 7 // the Free Software Foundation, either version 3 of the License, or 8 // (at your option) any later version. 9 // 10 // This program is distributed in the hope that it will be useful 11 // but WITHOUT ANY WARRANTY; without even the implied warranty of 12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 // GNU Affero General Public License for more details. 14 // 15 // You should have received a copy of the GNU Affero General Public License 16 // along with this program. If not, see <http://www.gnu.org/licenses/>. 17 18 package event 19 20 import ( 21 "testing" 22 ) 23 24 func TestARNString(t *testing.T) { 25 testCases := []struct { 26 arn ARN 27 expectedResult string 28 }{ 29 {ARN{}, ""}, 30 {ARN{TargetID{"1", "webhook"}, ""}, "arn:minio:s3-object-lambda::1:webhook"}, 31 {ARN{TargetID{"1", "webhook"}, "us-east-1"}, "arn:minio:s3-object-lambda:us-east-1:1:webhook"}, 32 } 33 34 for i, testCase := range testCases { 35 result := testCase.arn.String() 36 37 if result != testCase.expectedResult { 38 t.Fatalf("test %v: result: expected: %v, got: %v", i+1, testCase.expectedResult, result) 39 } 40 } 41 } 42 43 func TestParseARN(t *testing.T) { 44 testCases := []struct { 45 s string 46 expectedARN *ARN 47 expectErr bool 48 }{ 49 {"", nil, true}, 50 {"arn:minio:s3-object-lambda:::", nil, true}, 51 {"arn:minio:s3-object-lambda::1:webhook:remote", nil, true}, 52 {"arn:aws:s3-object-lambda::1:webhook", nil, true}, 53 {"arn:minio:sns::1:webhook", nil, true}, 54 {"arn:minio:s3-object-lambda::1:webhook", &ARN{TargetID{"1", "webhook"}, ""}, false}, 55 {"arn:minio:s3-object-lambda:us-east-1:1:webhook", &ARN{TargetID{"1", "webhook"}, "us-east-1"}, false}, 56 } 57 58 for i, testCase := range testCases { 59 arn, err := ParseARN(testCase.s) 60 expectErr := (err != nil) 61 62 if expectErr != testCase.expectErr { 63 t.Fatalf("test %v: error: expected: %v, got: %v", i+1, testCase.expectErr, expectErr) 64 } 65 66 if !testCase.expectErr { 67 if *arn != *testCase.expectedARN { 68 t.Fatalf("test %v: data: expected: %v, got: %v", i+1, testCase.expectedARN, arn) 69 } 70 } 71 } 72 }