go.temporal.io/server@v1.23.0/common/archiver/uri_test.go (about) 1 // The MIT License 2 // 3 // Copyright (c) 2020 Temporal Technologies Inc. All rights reserved. 4 // 5 // Copyright (c) 2020 Uber Technologies, Inc. 6 // 7 // Permission is hereby granted, free of charge, to any person obtaining a copy 8 // of this software and associated documentation files (the "Software"), to deal 9 // in the Software without restriction, including without limitation the rights 10 // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 11 // copies of the Software, and to permit persons to whom the Software is 12 // furnished to do so, subject to the following conditions: 13 // 14 // The above copyright notice and this permission notice shall be included in 15 // all copies or substantial portions of the Software. 16 // 17 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 20 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 21 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 23 // THE SOFTWARE. 24 25 package archiver 26 27 import ( 28 "testing" 29 30 "github.com/stretchr/testify/require" 31 "github.com/stretchr/testify/suite" 32 ) 33 34 type ( 35 URISuite struct { 36 *require.Assertions 37 suite.Suite 38 } 39 ) 40 41 func TestURISuite(t *testing.T) { 42 suite.Run(t, new(URISuite)) 43 } 44 45 func (s *URISuite) SetupTest() { 46 s.Assertions = require.New(s.T()) 47 } 48 49 func (s *URISuite) TestURI() { 50 testCases := []struct { 51 URIString string 52 valid bool 53 scheme string 54 path string 55 hostname string 56 port string 57 username string 58 password string 59 opaque string 60 query map[string][]string 61 }{ 62 { 63 URIString: "", 64 valid: false, 65 }, 66 { 67 URIString: "some random string", 68 valid: false, 69 }, 70 { 71 URIString: "mailto:a@b.com", 72 valid: true, 73 scheme: "mailto", 74 opaque: "a@b.com", 75 }, 76 { 77 URIString: "test://", 78 valid: true, 79 scheme: "test", 80 }, 81 { 82 URIString: "http://example.com/path", 83 valid: true, 84 scheme: "http", 85 hostname: "example.com", 86 path: "/path", 87 }, 88 { 89 URIString: "http://example.com/path with space", 90 valid: true, 91 scheme: "http", 92 hostname: "example.com", 93 path: "/path with space", 94 }, 95 { 96 URIString: "https://localhost:8080?key1=value1&key1=value2&key2=value3", 97 valid: true, 98 scheme: "https", 99 hostname: "localhost", 100 port: "8080", 101 query: map[string][]string{ 102 "key1": {"value1", "value2"}, 103 "key2": {"value3"}, 104 }, 105 }, 106 { 107 URIString: "file:///absolute/path/to/dir", 108 valid: true, 109 scheme: "file", 110 path: "/absolute/path/to/dir", 111 }, 112 { 113 URIString: "test://person:password@host/path", 114 valid: true, 115 scheme: "test", 116 hostname: "host", 117 path: "/path", 118 username: "person", 119 password: "password", 120 }, 121 { 122 URIString: "test:opaque?key1=value1&key1=value2&key2=value3", 123 valid: true, 124 scheme: "test", 125 opaque: "opaque", 126 query: map[string][]string{ 127 "key1": {"value1", "value2"}, 128 "key2": {"value3"}, 129 }, 130 }, 131 } 132 133 for _, tc := range testCases { 134 URI, err := NewURI(tc.URIString) 135 if !tc.valid { 136 s.Error(err) 137 continue 138 } 139 140 s.NoError(err) 141 s.Equal(tc.scheme, URI.Scheme()) 142 s.Equal(tc.path, URI.Path()) 143 s.Equal(tc.hostname, URI.Hostname()) 144 s.Equal(tc.port, URI.Port()) 145 s.Equal(tc.username, URI.Username()) 146 s.Equal(tc.password, URI.Password()) 147 s.Equal(tc.opaque, URI.Opaque()) 148 if tc.query != nil { 149 s.Equal(tc.query, URI.Query()) 150 } 151 } 152 }