37 lines
630 B
Go
37 lines
630 B
Go
package auction
|
|
|
|
import "testing"
|
|
|
|
func TestCar(t *testing.T) {
|
|
c := NewCar()
|
|
c.Title = "title"
|
|
c.Bid = "bid"
|
|
c.Watched = true
|
|
c.Details = map[string]string{"a": "b"}
|
|
d := c.Copy()
|
|
if !c.Equals(d) {
|
|
t.Errorf("equals failed post copy")
|
|
}
|
|
c.Details = map[string]string{"a": "c"}
|
|
if c.Equals(d) {
|
|
t.Errorf("equals passes post edit")
|
|
}
|
|
t.Log(c.String())
|
|
|
|
b, err := c.Encode()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
e := NewCar()
|
|
if err := e.Decode(b); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !c.Equals(e) {
|
|
t.Fatalf("decoded != encoded: %v vs %v", c, e)
|
|
}
|
|
|
|
if _, err := c.MarshalJSON(); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|