Skip to content

Commit

Permalink
Uppsf 127 improve test coverage (#22)
Browse files Browse the repository at this point in the history
* Add test for new handler
uses mock http-server

* Add map handler test

* Format with gofmt

* Bump go version to 1.10

* Update to golang:1.11

* Resolve #22
  • Loading branch information
Emil Dimitrov committed Jan 8, 2019
1 parent 92a412e commit ed005b4
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions video/events_handler_test.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,53 @@
package video

import (
"testing"

"github.com/Financial-Times/message-queue-go-producer/producer"
"github.com/Financial-Times/message-queue-gonsumer/consumer"
"github.com/gorilla/mux"
"github.com/stretchr/testify/assert"
"net/http"
"net/http/httptest"
"testing"
)

type mockMessageProducer struct {
message string
sendCalled bool
}

func TestNewVideoMapperHandler(t *testing.T) {
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
}))

cfg := producer.MessageProducerConfig{
Addr: "localhost:3000",
Topic: "writeTopic",
Queue: "writeQueue",
Authorization: "authorization",
}

handler := NewVideoMapperHandler(cfg, s.Client())
assert.NotNil(t, handler.messageProducer, "Message producer should be set")
assert.NotNil(t, handler.videoMapper, "Video mapper should be set")
}

func TestMapHandler_InvalidBody(t *testing.T) {
req, err := http.NewRequest("POST", "/map", http.NoBody)
if err != nil {
t.Fatal(err)
}

res := httptest.NewRecorder()

eventsHandler, _ := createEventsHandler()

r := mux.NewRouter()
r.HandleFunc("/map", eventsHandler.MapHandler).Methods("POST")
r.ServeHTTP(res, req)

assert.Equal(t, http.StatusBadRequest, res.Code, "Unexpected status code")
}

func TestOnMessage_InvalidSystemId(t *testing.T) {
m := consumer.Message{
Headers: map[string]string{
Expand Down

0 comments on commit ed005b4

Please sign in to comment.