go-gemini/gemini_test.go
2020-09-28 15:33:15 -04:00

47 lines
911 B
Go

package gmi
import (
"math/rand"
"testing"
"time"
)
func TestServeMuxEntryOrder(t *testing.T) {
expected := []string{
"https://example.com/longpath",
"https://example.com/path",
"https://example.com",
"http://example.com/longpath",
"http://example.com/path",
"http://example.com",
"example.com/longpath",
"example.com/path",
"example.com",
"/longpath",
"/path",
"/",
}
// Shuffle input
a := make([]string, len(expected))
copy(a, expected)
rand.Seed(time.Now().UnixNano())
rand.Shuffle(len(a), func(i, j int) { a[i], a[j] = a[j], a[i] })
mux := &ServeMux{}
for _, s := range a {
mux.Handle(s, NotFoundHandler())
var es string
for i := range mux.es {
es += mux.es[i].u.String() + " "
}
t.Logf(es)
}
for i, e := range mux.es {
s := e.u.String()
if s != expected[i] {
t.Errorf("wrong order of mux entries: expected %s, got %s", expected[i], s)
}
}
}