Codebase list golang-github-go-kit-kit / 4a29204 transport / http / request_response_funcs_test.go
4a29204

Tree @4a29204 (Download .tar.gz)

request_response_funcs_test.go @4a29204raw · history · blame

package http_test

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

	httptransport "github.com/go-kit/kit/transport/http"
)

func TestSetHeader(t *testing.T) {
	const (
		key = "X-Foo"
		val = "12345"
	)
	r := httptest.NewRecorder()
	httptransport.SetResponseHeader(key, val)(context.Background(), r)
	if want, have := val, r.Header().Get(key); want != have {
		t.Errorf("want %q, have %q", want, have)
	}
}

func TestSetContentType(t *testing.T) {
	const contentType = "application/json"
	r := httptest.NewRecorder()
	httptransport.SetContentType(contentType)(context.Background(), r)
	if want, have := contentType, r.Header().Get("Content-Type"); want != have {
		t.Errorf("want %q, have %q", want, have)
	}
}