rproxy3/storage/packable/packable_test.go

48 lines
909 B
Go

package packable
import (
"net/url"
"testing"
)
func TestPackableString(t *testing.T) {
raw := "hello"
s := NewString(raw)
if s.String() != raw {
t.Errorf("cannot convert string to String: %v vs %v", s, raw)
}
packed, err := s.Encode()
if err != nil {
t.Errorf("cannot encode String: %v", err)
}
x := NewString("")
if err := x.Decode(packed); err != nil {
t.Errorf("cannot decode string: %v", err)
} else if x.String() != raw {
t.Errorf("wrong decoded string: %v vs %v", x, raw)
}
}
func TestPackableURL(t *testing.T) {
raw := &url.URL{
Scheme: "a",
Host: "b",
Path: "c",
}
s := NewURL(raw)
packed, err := s.Encode()
if err != nil {
t.Errorf("cannot encode URL: %v", err)
}
x := NewURL()
if err := x.Decode(packed); err != nil {
t.Errorf("cannot decode URL: %v", err)
} else if *x != *s {
t.Errorf("wrong decoded URL: %v (%T) vs %v (%T)", x, x, s, s)
}
}