zv_test.go 914 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package rest_test
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "log"
  6. "testing"
  7. mjson "git.ali33.ru/fcg-xvii/go-tools/json"
  8. "git.ali33.ru/fcg-xvii/rest"
  9. )
  10. type CTest struct {
  11. Conditions []*rest.Condition
  12. }
  13. func TestSerializeList(t *testing.T) {
  14. jm := mjson.Map{}
  15. src := []byte(`{
  16. "conditions": [
  17. {
  18. "field": "prefix",
  19. "operator": "=",
  20. "value": "okko"
  21. }
  22. ]
  23. }`)
  24. buf := bytes.NewBuffer(src)
  25. err := json.NewDecoder(buf).Decode(&jm)
  26. if err != nil {
  27. //responseError(w, rest.ErrorMessage("ErrDataParse", err.Error()), 500)
  28. t.Fatal(err)
  29. return
  30. }
  31. /*
  32. jm := json.Map{
  33. "conditions": []map[string]any{
  34. {
  35. "field": "prefix",
  36. "operator": "=",
  37. "value": "00000",
  38. "logic": "and",
  39. },
  40. },
  41. }
  42. */
  43. c := &CTest{}
  44. t.Log(jm)
  45. err = rest.Serialize(jm, &c)
  46. if err != nil {
  47. log.Println("!!!!!!!!!!!!!!!")
  48. t.Fatal(err)
  49. }
  50. t.Log(c.Conditions[0])
  51. }