Sha256: aeefbf042f4fe0d5d54cdde0c073289c21a59ddca31be13348ef8901d07626a5

Contents?: true

Size: 899 Bytes

Versions: 3

Compression:

Stored size: 899 Bytes

Contents

package handlers

import (
	"context"
	"encoding/json"
	"net/http"
	"net/http/httptest"
	"testing"

	log "github.com/Sirupsen/logrus"
	"github.com/stretchr/testify/assert"
)

func echoTestSetup(t *testing.T) http.Handler {
	deps := echoHandlerDependencies{
		logger: &log.Logger{},
	}

	return newEchoHandler(deps)
}

func TestEchoHandlerCorrectlyEchosResponse(t *testing.T) {
	h := echoTestSetup(t)

	var responseRecorder *httptest.ResponseRecorder
	r := httptest.NewRequest("POST", "/echo", nil)

	responseRecorder = httptest.NewRecorder()

	echo := Echo{Echo: "Hello World"}
	c := context.WithValue(context.Background(), validationRequestKey{}, echo)
	r = r.WithContext(c)

	h.ServeHTTP(responseRecorder, r)

	body := responseRecorder.Body.Bytes()
	response := Echo{}
	json.Unmarshal(body, &response)

	assert.Equal(t, 200, responseRecorder.Code)
	assert.Equal(t, response.Echo, "Hello World")
}

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
minke-generator-go-0.9.3 lib/generators/gomicroservice/scaffold/handlers/echo_test.go.erb
minke-generator-go-0.9.2 lib/generators/gomicroservice/scaffold/handlers/echo_test.go.erb
minke-generator-go-0.9.1 lib/generators/gomicroservice/scaffold/handlers/echo_test.go.erb