39 lines
780 B
Go
39 lines
780 B
Go
|
|
package invite
|
||
|
|
|
||
|
|
import "testing"
|
||
|
|
|
||
|
|
func TestRoundTrip(t *testing.T) {
|
||
|
|
s, err := Encode("ws://my-vps:17339/ws", "friends")
|
||
|
|
if err != nil {
|
||
|
|
t.Fatalf("Encode: %v", err)
|
||
|
|
}
|
||
|
|
if len(s) < 7 || s[:6] != "waste:" {
|
||
|
|
t.Fatalf("expected waste: prefix, got %q", s)
|
||
|
|
}
|
||
|
|
|
||
|
|
inv, err := Decode(s)
|
||
|
|
if err != nil {
|
||
|
|
t.Fatalf("Decode: %v", err)
|
||
|
|
}
|
||
|
|
if inv.Anchor != "ws://my-vps:17339/ws" {
|
||
|
|
t.Fatalf("anchor = %q", inv.Anchor)
|
||
|
|
}
|
||
|
|
if inv.Network != "friends" {
|
||
|
|
t.Fatalf("network = %q", inv.Network)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestDecodeInvalid(t *testing.T) {
|
||
|
|
cases := []string{
|
||
|
|
"",
|
||
|
|
"notaninvite",
|
||
|
|
"waste:!!!",
|
||
|
|
"waste:" + "eyJhbmNob3IiOiIifQ==", // missing network
|
||
|
|
}
|
||
|
|
for _, c := range cases {
|
||
|
|
if _, err := Decode(c); err == nil {
|
||
|
|
t.Errorf("Decode(%q) expected error, got nil", c)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|