| 191 | } |
| 192 | |
| 193 | func TestCanonize(t *testing.T) { |
| 194 | t.Parallel() |
| 195 | |
| 196 | tests := []struct { |
| 197 | name string |
| 198 | input string |
| 199 | expected string |
| 200 | }{ |
| 201 | { |
| 202 | name: "trailing_slash", |
| 203 | input: "https://example.com/", |
| 204 | expected: "https://example.com", |
| 205 | }, |
| 206 | { |
| 207 | name: "leading_and_trailing_whitespace", |
| 208 | input: " https://example.com ", |
| 209 | expected: "https://example.com", |
| 210 | }, |
| 211 | { |
| 212 | name: "trailing_slash_and_whitespace", |
| 213 | input: " https://example.com/ ", |
| 214 | expected: "https://example.com", |
| 215 | }, |
| 216 | { |
| 217 | name: "no_trailing_slash", |
| 218 | input: "https://example.com", |
| 219 | expected: "https://example.com", |
| 220 | }, |
| 221 | { |
| 222 | name: "path_with_trailing_slash", |
| 223 | input: "https://example.com/path/", |
| 224 | expected: "https://example.com/path", |
| 225 | }, |
| 226 | { |
| 227 | name: "empty_string", |
| 228 | input: "", |
| 229 | expected: "", |
| 230 | }, |
| 231 | { |
| 232 | name: "only_whitespace", |
| 233 | input: " ", |
| 234 | expected: "", |
| 235 | }, |
| 236 | } |
| 237 | |
| 238 | for _, tt := range tests { |
| 239 | t.Run(tt.name, func(t *testing.T) { |
| 240 | t.Parallel() |
| 241 | |
| 242 | result := canonize(tt.input) |
| 243 | |
| 244 | assert.Equal(t, tt.expected, result) |
| 245 | }) |
| 246 | } |
| 247 | } |
| 248 | |
| 249 | func TestDefaultModelLogic(t *testing.T) { |
| 250 | tests := []struct { |