33 lines
829 B
Go
33 lines
829 B
Go
package contract
|
|
|
|
import (
|
|
"encoding/json"
|
|
"git.ipao.vip/rogee/go-sip/contracts"
|
|
"testing"
|
|
)
|
|
|
|
func TestDecodeMQCommandV1(t *testing.T) {
|
|
for _, name := range []string{"call-execute", "task-control", "call-replay", "command-replay"} {
|
|
raw, err := contracts.Files.ReadFile("upstream/" + MQSourceCommit + "/examples/" + name + ".json")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
message, err := DecodeMQCommand(raw)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if message.DispatcherID == "" || message.CommandType == "" {
|
|
t.Fatal("command identity lost")
|
|
}
|
|
var changed map[string]any
|
|
if err := json.Unmarshal(raw, &changed); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
changed["schema_version"] = "1.0"
|
|
bad, _ := json.Marshal(changed)
|
|
if _, err := DecodeMQCommand(bad); err == nil {
|
|
t.Fatal("legacy command accepted")
|
|
}
|
|
}
|
|
}
|