github.com/minio/console@v1.3.0/api/client_test.go (about) 1 // This file is part of MinIO Console Server 2 // Copyright (c) 2021 MinIO, Inc. 3 // 4 // This program is free software: you can redistribute it and/or modify 5 // it under the terms of the GNU Affero General Public License as published by 6 // the Free Software Foundation, either version 3 of the License, or 7 // (at your option) any later version. 8 // 9 // This program is distributed in the hope that it will be useful, 10 // but WITHOUT ANY WARRANTY; without even the implied warranty of 11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 // GNU Affero General Public License for more details. 13 // 14 // You should have received a copy of the GNU Affero General Public License 15 // along with this program. If not, see <http://www.gnu.org/licenses/>. 16 17 package api 18 19 import "testing" 20 21 func Test_computeObjectURLWithoutEncode(t *testing.T) { 22 type args struct { 23 bucketName string 24 prefix string 25 } 26 tests := []struct { 27 name string 28 args args 29 want string 30 wantErr bool 31 }{ 32 { 33 name: "http://localhost:9000/bucket-1/小飼弾小飼弾小飼弾.jp", 34 args: args{ 35 bucketName: "bucket-1", 36 prefix: "小飼弾小飼弾小飼弾.jpg", 37 }, 38 want: "http://localhost:9000/bucket-1/小飼弾小飼弾小飼弾.jpg", 39 wantErr: false, 40 }, 41 { 42 name: "http://localhost:9000/bucket-1/a a - a a & a a - a a a.jpg", 43 args: args{ 44 bucketName: "bucket-1", 45 prefix: "a a - a a & a a - a a a.jpg", 46 }, 47 want: "http://localhost:9000/bucket-1/a a - a a & a a - a a a.jpg", 48 wantErr: false, 49 }, 50 { 51 name: "http://localhost:9000/bucket-1/02%20-%20FLY%20ME%20TO%20THE%20MOON%20.jpg", 52 args: args{ 53 bucketName: "bucket-1", 54 prefix: "02%20-%20FLY%20ME%20TO%20THE%20MOON%20.jpg", 55 }, 56 want: "http://localhost:9000/bucket-1/02%20-%20FLY%20ME%20TO%20THE%20MOON%20.jpg", 57 wantErr: false, 58 }, 59 { 60 name: "http://localhost:9000/bucket-1/!@#$%^&*()_+.jpg", 61 args: args{ 62 bucketName: "bucket-1", 63 prefix: "!@#$%^&*()_+.jpg", 64 }, 65 want: "http://localhost:9000/bucket-1/!@#$%^&*()_+.jpg", 66 wantErr: false, 67 }, 68 { 69 name: "http://localhost:9000/bucket-1/test/test2/小飼弾小飼弾小飼弾.jpg", 70 args: args{ 71 bucketName: "bucket-1", 72 prefix: "test/test2/小飼弾小飼弾小飼弾.jpg", 73 }, 74 want: "http://localhost:9000/bucket-1/test/test2/小飼弾小飼弾小飼弾.jpg", 75 wantErr: false, 76 }, 77 } 78 for _, tt := range tests { 79 t.Run(tt.name, func(_ *testing.T) { 80 got, err := computeObjectURLWithoutEncode(tt.args.bucketName, tt.args.prefix) 81 if (err != nil) != tt.wantErr { 82 t.Errorf("computeObjectURLWithoutEncode() errors = %v, wantErr %v", err, tt.wantErr) 83 return 84 } 85 if got != tt.want { 86 t.Errorf("computeObjectURLWithoutEncode() got = %v, want %v", got, tt.want) 87 } 88 }) 89 } 90 }