Fixed malformed json for chans command

Mentioned by ds2xor on Slack
This commit is contained in:
tidwall 2019-08-03 10:10:28 -07:00
parent 544c414972
commit f7888c1edf
2 changed files with 23 additions and 1 deletions

View File

@ -393,8 +393,9 @@ func (c *Server) cmdHooks(msg *Message, channel bool) (
}
buf.WriteString(jsonString(endpoint))
}
buf.WriteString(`]`)
}
buf.WriteString(`],"command":[`)
buf.WriteString(`,"command":[`)
for i, v := range hook.Message.Args {
if i > 0 {
buf.WriteString(`,`)

View File

@ -27,6 +27,9 @@ func subTestFence(t *testing.T, mc *mockServer) {
runStep(t, mc, "roaming live", fence_roaming_live_test)
runStep(t, mc, "roaming channel", fence_roaming_channel_test)
runStep(t, mc, "roaming webhook", fence_roaming_webhook_test)
// channel meta
runStep(t, mc, "channel meta", fence_channel_meta_test)
}
type fenceReader struct {
@ -312,3 +315,21 @@ func do(c redis.Conn, cmd string) (interface{}, error) {
// Perform the request and return the response
return c.Do(params[0], args...)
}
func fence_channel_meta_test(mc *mockServer) error {
return mc.DoBatch([][]interface{}{
{"SETCHAN", "carbon", "NEARBY", "x", "MATCH", "carbon*", "FENCE", "NODWELL", "points", "ROAM", "x", "*", "200000"}, {"1"},
{"OUTPUT", "json"}, {`{"ok":true}`},
// check for valid json on the chans command
{"CHANS", "*"}, {
func(v interface{}) (resp, expect interface{}) {
// v is the value as strings or slices of strings
// test will pass as long as `resp` and `expect` are the same.
if !json.Valid([]byte(v.(string))) {
return v, "Valid JSON"
}
return true, true
},
},
})
}