| 1 | // Copyright 2015 Matthew Holt and The Caddy Authors |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package fileserverscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/ |
| 16 | |
| 17 | import ( |
| 18 | "testingscip-go gomod github.com/golang/go/src go1.25.1 testing/" |
| 19 | ) |
| 20 | |
| 21 | func TestBreadcrumbsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/TestBreadcrumbs().(t *testingscip-go gomod github.com/golang/go/src go1.25.1 testing/.Tscip-go gomod github.com/golang/go/src go1.25.1 testing/T#) { |
| 22 | testdata := []struct { |
| 23 | path string |
| 24 | expected []crumbscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb# |
| 25 | }{ |
| 26 | {"", []crumbscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#{}}, |
| 27 | {"/", []crumbscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#{{Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "/"}}}, |
| 28 | {"/foo/", []crumbscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#{ |
| 29 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "/"}, |
| 30 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "foo"}, |
| 31 | }}, |
| 32 | {"/foo/bar/", []crumbscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#{ |
| 33 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "/"}, |
| 34 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "foo"}, |
| 35 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "bar"}, |
| 36 | }}, |
| 37 | {"/foo bar/", []crumbscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#{ |
| 38 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "/"}, |
| 39 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "foo bar"}, |
| 40 | }}, |
| 41 | {"/foo bar/baz/", []crumbscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#{ |
| 42 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "/"}, |
| 43 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "foo bar"}, |
| 44 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "baz"}, |
| 45 | }}, |
| 46 | {"/100%25 test coverage/is a lie/", []crumbscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#{ |
| 47 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "/"}, |
| 48 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "100% test coverage"}, |
| 49 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "is a lie"}, |
| 50 | }}, |
| 51 | {"/AC%2FDC/", []crumbscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#{ |
| 52 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "/"}, |
| 53 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "AC/DC"}, |
| 54 | }}, |
| 55 | {"/foo/%2e%2e%2f/bar", []crumbscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#{ |
| 56 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../../../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "/"}, |
| 57 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "foo"}, |
| 58 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "../"}, |
| 59 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "bar"}, |
| 60 | }}, |
| 61 | {"/foo/../bar", []crumbscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#{ |
| 62 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../../../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "/"}, |
| 63 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "foo"}, |
| 64 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: ".."}, |
| 65 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "bar"}, |
| 66 | }}, |
| 67 | {"foo/bar/baz", []crumbscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#{ |
| 68 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "foo"}, |
| 69 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "bar"}, |
| 70 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "baz"}, |
| 71 | }}, |
| 72 | {"/qux/quux/corge/", []crumbscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#{ |
| 73 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../../../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "/"}, |
| 74 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "qux"}, |
| 75 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "quux"}, |
| 76 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "corge"}, |
| 77 | }}, |
| 78 | {"/مجلد/", []crumbscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#{ |
| 79 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "/"}, |
| 80 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "مجلد"}, |
| 81 | }}, |
| 82 | {"/مجلد-1/مجلد-2", []crumbscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#{ |
| 83 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "/"}, |
| 84 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "مجلد-1"}, |
| 85 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "مجلد-2"}, |
| 86 | }}, |
| 87 | {"/مجلد%2F1", []crumbscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#{ |
| 88 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "../", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "/"}, |
| 89 | {Linkscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Link.: "", Textscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/crumb#Text.: "مجلد/1"}, |
| 90 | }}, |
| 91 | } |
| 92 | |
| 93 | for testNum, d := range testdata { |
| 94 | l := browseTemplateContextscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#{Pathscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Path.: d.path} |
| 95 | actual := l.Breadcrumbsscip-go gomod github.com/caddyserver/caddy/v2 . `github.com/caddyserver/caddy/v2/modules/caddyhttp/fileserver`/browseTemplateContext#Breadcrumbs().() |
| 96 | if len(actual) != len(d.expected) { |
| 97 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Test %d: Got %d components but expected %d; got: %+v", testNum, len(actual), len(d.expected), actual) |
| 98 | continue |
| 99 | } |
| 100 | for i, c := range actual { |
| 101 | if c != d.expected[i] { |
| 102 | t.Errorfscip-go gomod github.com/golang/go/src go1.25.1 testing/common#Errorf().("Test %d crumb %d: got %#v but expected %#v at index %d", testNum, i, c, d.expected[i], i) |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | } |