1
0
mirror of https://git.sr.ht/~adnano/go-gemini synced 2024-11-23 16:52:06 +01:00
go-gemini/gemini_test.go
2020-09-25 11:27:26 -04:00

42 lines
810 B
Go

package gemini
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)
}
}
}