github.com/thanos-io/thanos@v0.32.5/pkg/ui/ui_test.go (about) 1 // Copyright (c) The Thanos Authors. 2 // Licensed under the Apache License 2.0. 3 4 package ui 5 6 import "testing" 7 8 func TestSanitizePrefix(t *testing.T) { 9 type args struct { 10 prefix string 11 } 12 tests := []struct { 13 name string 14 args args 15 want string 16 wantErr bool 17 }{ 18 { 19 "InvalidEscaping", 20 args{ 21 prefix: "/%%", 22 }, 23 "", 24 true, 25 }, 26 { 27 "URL", 28 args{ 29 prefix: "http://www.example.com/some%20path/two?foo=bar?foo1=bar1#id", 30 }, 31 "/some path/two", 32 false, 33 }, 34 { 35 "DelimiterNotAllowed", 36 args{ 37 prefix: "http://www.example.com/host%3A%2F%2Fpath/", 38 }, 39 "/host:/path", 40 false, 41 }, 42 { 43 "EmptyPrefix", 44 args{ 45 prefix: "", 46 }, 47 "", 48 false, 49 }, 50 { 51 "Root", 52 args{ 53 prefix: "/", 54 }, 55 "", 56 false, 57 }, 58 } 59 for _, tt := range tests { 60 t.Run(tt.name, func(t *testing.T) { 61 got, err := SanitizePrefix(tt.args.prefix) 62 if (err != nil) != tt.wantErr { 63 t.Errorf("SanitizePrefix() error = %v, wantErr %v", err, tt.wantErr) 64 return 65 } 66 if got != tt.want { 67 t.Errorf("SanitizePrefix() = %v, want %v", got, tt.want) 68 } 69 }) 70 } 71 }