github.com/minio/minio@v0.0.0-20240328213742-3f72439b8a27/internal/arn/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 arn 19 20 import ( 21 "fmt" 22 "testing" 23 ) 24 25 func TestNewIAMRoleARN(t *testing.T) { 26 testCases := []struct { 27 resourceID string 28 serverRegion string 29 expectedARN string 30 isErrExpected bool 31 }{ 32 { 33 resourceID: "myrole", 34 serverRegion: "us-east-1", 35 expectedARN: "arn:minio:iam:us-east-1::role/myrole", 36 isErrExpected: false, 37 }, 38 { 39 resourceID: "myrole", 40 serverRegion: "", 41 expectedARN: "arn:minio:iam:::role/myrole", 42 isErrExpected: false, 43 }, 44 { 45 // Resource ID can start with a hyphen 46 resourceID: "-myrole", 47 serverRegion: "", 48 expectedARN: "arn:minio:iam:::role/-myrole", 49 isErrExpected: false, 50 }, 51 { 52 resourceID: "", 53 serverRegion: "", 54 expectedARN: "", 55 isErrExpected: true, 56 }, 57 } 58 for i, testCase := range testCases { 59 arn, err := NewIAMRoleARN(testCase.resourceID, testCase.serverRegion) 60 fmt.Println(arn, err) 61 if err != nil { 62 if !testCase.isErrExpected { 63 t.Errorf("Test %d: Unexpected error: %v", i+1, err) 64 } 65 continue 66 } 67 68 if testCase.isErrExpected { 69 t.Errorf("Test %d: Expected error but got none", i+1) 70 } 71 if arn.String() != testCase.expectedARN { 72 t.Errorf("Test %d: Expected ARN %s but got %s", i+1, testCase.expectedARN, arn.String()) 73 } 74 75 } 76 }