github.com/minio/mc@v0.0.0-20240503112107-b471de8d1882/cmd/client-url_test.go (about) 1 // Copyright (c) 2015-2022 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 cmd 19 20 import checkv1 "gopkg.in/check.v1" 21 22 // TestURL - tests url parsing and fields. 23 func (s *TestSuite) TestURL(c *checkv1.C) { 24 urlStr := "foo?.go" 25 url := newClientURL(urlStr) 26 c.Assert(url.Path, checkv1.Equals, "foo?.go") 27 28 urlStr = "https://s3.amazonaws.com/mybucket/foo?.go" 29 url = newClientURL(urlStr) 30 c.Assert(url.Scheme, checkv1.Equals, "https") 31 c.Assert(url.Host, checkv1.Equals, "s3.amazonaws.com") 32 c.Assert(url.Path, checkv1.Equals, "/mybucket/foo?.go") 33 } 34 35 // TestURLJoinPath - tests joining two different urls. 36 func (s *TestSuite) TestURLJoinPath(c *checkv1.C) { 37 // Join two URLs 38 url1 := "http://s3.mycompany.io/dev" 39 url2 := "http://s3.aws.amazon.com/mybucket/bin/zgrep" 40 url := urlJoinPath(url1, url2) 41 c.Assert(url, checkv1.Equals, "http://s3.mycompany.io/dev/mybucket/bin/zgrep") 42 43 // Join URL and a path 44 url1 = "http://s3.mycompany.io/dev" 45 url2 = "mybucket/bin/zgrep" 46 url = urlJoinPath(url1, url2) 47 c.Assert(url, checkv1.Equals, "http://s3.mycompany.io/dev/mybucket/bin/zgrep") 48 49 // Check if it strips URL2's tailing `/` 50 url1 = "http://s3.mycompany.io/dev" 51 url2 = "mybucket/bin/" 52 url = urlJoinPath(url1, url2) 53 c.Assert(url, checkv1.Equals, "http://s3.mycompany.io/dev/mybucket/bin/") 54 }