status_test.go 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. package manager
  2. import (
  3. "encoding/json"
  4. "testing"
  5. "time"
  6. tunasync "github.com/tuna/tunasync/internal"
  7. . "github.com/smartystreets/goconvey/convey"
  8. )
  9. func TestStatus(t *testing.T) {
  10. Convey("status json ser-de should work", t, func() {
  11. tz := "Asia/Shanghai"
  12. loc, err := time.LoadLocation(tz)
  13. So(err, ShouldBeNil)
  14. m := mirrorStatus{
  15. Name: "tunalinux",
  16. Status: tunasync.Success,
  17. LastUpdate: time.Date(2016, time.April, 16, 23, 8, 10, 0, loc),
  18. Size: "5GB",
  19. Upstream: "rsync://mirrors.tuna.tsinghua.edu.cn/tunalinux/",
  20. }
  21. b, err := json.Marshal(m)
  22. So(err, ShouldBeNil)
  23. // fmt.Println(string(b))
  24. var m2 mirrorStatus
  25. err = json.Unmarshal(b, &m2)
  26. So(err, ShouldBeNil)
  27. // fmt.Printf("%#v", m2)
  28. So(m2.Name, ShouldEqual, m.Name)
  29. So(m2.Status, ShouldEqual, m.Status)
  30. So(m2.LastUpdate.Unix(), ShouldEqual, m.LastUpdate.Unix())
  31. So(m2.LastUpdate.UnixNano(), ShouldEqual, m.LastUpdate.UnixNano())
  32. So(m2.Size, ShouldEqual, m.Size)
  33. So(m2.Upstream, ShouldEqual, m.Upstream)
  34. })
  35. }