|
@@ -0,0 +1,62 @@
|
|
|
|
+package rest_test
|
|
|
|
+
|
|
|
|
+import (
|
|
|
|
+ "bytes"
|
|
|
|
+ "encoding/json"
|
|
|
|
+ "log"
|
|
|
|
+ "testing"
|
|
|
|
+
|
|
|
|
+ mjson "git.ali33.ru/fcg-xvii/go-tools/json"
|
|
|
|
+ "git.ali33.ru/fcg-xvii/rest"
|
|
|
|
+)
|
|
|
|
+
|
|
|
|
+type CTest struct {
|
|
|
|
+ Conditions []*rest.Condition
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+func TestSerializeList(t *testing.T) {
|
|
|
|
+ jm := mjson.Map{}
|
|
|
|
+
|
|
|
|
+ src := []byte(`{
|
|
|
|
+ "conditions": [
|
|
|
|
+ {
|
|
|
|
+ "field": "prefix",
|
|
|
|
+ "operator": "=",
|
|
|
|
+ "value": "okko"
|
|
|
|
+ }
|
|
|
|
+ ]
|
|
|
|
+ }`)
|
|
|
|
+
|
|
|
|
+ buf := bytes.NewBuffer(src)
|
|
|
|
+
|
|
|
|
+ err := json.NewDecoder(buf).Decode(&jm)
|
|
|
|
+ if err != nil {
|
|
|
|
+ //responseError(w, rest.ErrorMessage("ErrDataParse", err.Error()), 500)
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ return
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /*
|
|
|
|
+ jm := json.Map{
|
|
|
|
+ "conditions": []map[string]any{
|
|
|
|
+ {
|
|
|
|
+ "field": "prefix",
|
|
|
|
+ "operator": "=",
|
|
|
|
+ "value": "00000",
|
|
|
|
+ "logic": "and",
|
|
|
|
+ },
|
|
|
|
+ },
|
|
|
|
+ }
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+ c := &CTest{}
|
|
|
|
+
|
|
|
|
+ t.Log(jm)
|
|
|
|
+
|
|
|
|
+ err = rest.Serialize(jm, &c)
|
|
|
|
+ if err != nil {
|
|
|
|
+ log.Println("!!!!!!!!!!!!!!!")
|
|
|
|
+ t.Fatal(err)
|
|
|
|
+ }
|
|
|
|
+ t.Log(c.Conditions[0])
|
|
|
|
+}
|