go-gemini/gemini_test.go

42 lines
807 B
Go
Raw Normal View History

2020-09-27 18:20:59 -06:00
package gmi
2020-09-25 09:27:26 -06:00
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(expected, a)
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, nil)
}
for i, e := range mux.entries {
s := e.u.String()
if s != expected[i] {
t.Errorf("wrong order of mux entries: expected %s, got %s", expected[i], s)
}
}
}