示例#1
0
func init() {
	setup()
	var wrap data.Wrapper
	var msg data.Message
	wrap.Action = "Send"
	wrap.QueueID = "main"
	msg.Uuid = uuid.NewRandom().String()
	msg.Body = "Some exciting stuff"
	msg.Created = time.Now().Unix()
	msg.Persistent = true
	wrap.Message = msg
}
示例#2
0
func TestApiMessageStatus(t *testing.T) {
	var buf bytes.Buffer

	// Set up another test wrapper
	var tw data.Wrapper
	var msg data.Message
	msg.Uuid = uuid.NewRandom().String()
	msg.Body = "another test thing"
	msg.Route = []string{"default"}
	tw.Message = msg

	// Send the wrapper using the client
	cc := client.NewConnection(testcontext)
	err := cc.SendWrapper(&tw)
	if err != nil {
		log.Printf("Error using client to send wrapper : %v\n", err)
		t.Fatalf("%v\n", err)
	}

	// Check the message status using the web api
	var wr webmanager.StatusRequest
	wr.IsMessage = true
	wr.MessageUuid = msg.Uuid

	if err := json.NewEncoder(&buf).Encode(&wr); err != nil {
		t.Fatalf("%v\n", err)
	}

	resp, err := http.Post("http://127.0.0.1:8080/api/status", "application/json", &buf)
	if err != nil {
		t.Fatalf("%v\n", err)
	}
	if resp.StatusCode == 400 {
		t.Fatalf("Server returned 400 when checking message")
	}
	defer resp.Body.Close()
	var msr webmanager.MessageStatusResp
	if err := json.NewDecoder(resp.Body).Decode(&msr); err != nil {
		if err.Error() != "EOF" {
			t.Fatalf("%v\n", err)
		}
	}
	if msr.Status != "Received" {
		t.Fatalf("Message status response has the wrong message status")
	}
}