예제 #1
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")
	}
}
예제 #2
0
func TestClientSend(t *testing.T) {
	cc := client.NewConnection(testcontext)
	err := cc.SendWrapper(&wrap)
	if err != nil {
		log.Printf("Error using client to send wrapper : %v\n", err)
		t.Fail()
	}
	resp, err := http.Get("http://127.0.0.1:8080/api/status")
	if err != nil {
		t.Fail()
	}
	if resp.StatusCode != 200 {
		t.Fail()
	}
	defer resp.Body.Close()
	_, err = ioutil.ReadAll(resp.Body)
	if err != nil {
		t.Fail()
	}
}