MCPcopy Create free account
hub / github.com/DNAProject/DNA / TestParseParams

Function TestParseParams

cmd/utils/params_test.go:61–87  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

59}
60
61func TestParseParams(t *testing.T) {
62 testByteArray := []byte("HelloWorld")
63 testByteArrayParam := hex.EncodeToString(testByteArray)
64 rawParamStr := "bytearray:" + testByteArrayParam + ",string:foo,[int:0,[bool:true,string:bar],bool:false]"
65 params, err := ParseParams(rawParamStr)
66 if err != nil {
67 t.Errorf("TestParseParams error:%s", err)
68 return
69 }
70 data, err := json.Marshal(params)
71 if err != nil {
72 t.Errorf("json.Marshal error:%s", err)
73 return
74 }
75 fmt.Printf("%s\n", data)
76
77 expect := []interface{}{testByteArray, "foo", []interface{}{0, []interface{}{true, "bar"}, false}}
78 ok, err := arrayEqual(params, expect)
79 if err != nil {
80 t.Errorf("TestParseParams error:%s", err)
81 return
82 }
83 if !ok {
84 t.Errorf("TestParseParams faild, res:%s != %s", params, expect)
85 return
86 }
87}
88
89func arrayEqual(a1, a2 []interface{}) (bool, error) {
90 data1, err := json.Marshal(a1)

Callers

nothing calls this directly

Calls 4

ParseParamsFunction · 0.85
arrayEqualFunction · 0.85
ErrorfMethod · 0.80
MarshalMethod · 0.80

Tested by

no test coverage detected