batch_param_test.go 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package model
  2. import (
  3. . "github.com/smartystreets/goconvey/convey"
  4. "testing"
  5. )
  6. func TestBatchParam_Format(t *testing.T) {
  7. Convey("BatchParam_Format", t, func() {
  8. f := func(p *BatchParam, t *testing.T, args ...interface{}) {
  9. t.Logf("args(%+v)", args...)
  10. p.Handler(&p.Params, args...)
  11. t.Logf("params(%+v)\r\n", p)
  12. }
  13. var uuid interface{}
  14. m := map[string]interface{}{
  15. "h1": 10,
  16. "archive": &Archive{ID: int64(12)},
  17. }
  18. p1 := NewBatchParam(m, BaseParamHandler)
  19. f(p1, t)
  20. _, exist := p1.Params["uuid"]
  21. So(exist, ShouldEqual, false)
  22. p2 := NewBatchParam(m, PushParamHandler)
  23. f(p2, t)
  24. _, exist = p2.Params["uuid"]
  25. So(exist, ShouldEqual, true)
  26. uuid = p2.Params["uuid"]
  27. f(p2, t, []int{1, 2})
  28. _, exist = p2.Params["uuid"]
  29. So(exist, ShouldEqual, true)
  30. So(p2.Params["uuid"], ShouldNotEqual, uuid)
  31. f(p2, t, []int64{1, 2})
  32. _, exist = p2.Params["uuid"]
  33. So(exist, ShouldEqual, true)
  34. var h ParamHandler
  35. p2.Params["h1"] = 1
  36. t.Logf("params(%+v), %+v, %v", p2.Params, h, h == nil)
  37. })
  38. }