Skip to content

Instantly share code, notes, and snippets.

@kaneshin
Created November 28, 2016 16:17
Show Gist options
  • Save kaneshin/5fd14960360b9b55797ff302beee0bb0 to your computer and use it in GitHub Desktop.
Save kaneshin/5fd14960360b9b55797ff302beee0bb0 to your computer and use it in GitHub Desktop.
package main
import (
"io/ioutil"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestEchoHandler(t *testing.T) {
s := httptest.NewServer(http.HandlerFunc(EchoHandler("hello")))
res, err := http.Get(s.URL)
assert.NoError(t, err)
assert.Equal(t, "text/plain", res.Header.Get("Content-Type"))
assert.Equal(t, 200, res.StatusCode)
defer res.Body.Close()
body, err := ioutil.ReadAll(res.Body)
assert.NoError(t, err)
assert.Equal(t, "hello", string(body))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment