Categorygithub.com/goapt/test
repositorypackage
1.0.1
Repository: https://github.com/goapt/test.git
Documentation: pkg.go.dev

# README

Golang unit testing tools

Build Status codecov Go Report Card
GoDoc

go get github.com/goapt/test

HTTP Mock

var httpSuites = []test.HttpClientSuite{
    {
        URI: "/test",
        ResponseBody: `{"retcode":200}`,
    },
}

func TestLoginHandle(t *testing.T) {
	httpClient := test.NewHttpClientSuite(httpSuites)
    resp, err :=  httpClient.Post("https://dummy.impl/test",test.JsonContentType,strings.NewReader(""))
    assert.NoError(t, err)
    if err == nil {
        body, err := ioutil.ReadAll(resp.Body)
        assert.NoError(t, err)
        assert.Equal(t, `{"retcode":200}`, string(body))
    }
}

Redis memory server

Based on the github.com/alicebob/miniredis

rds := test.NewRedis()

Gee handler test

req := test.NewRequest("/test", func(c *gee.Context) gee.Response {
    return c.String("ok")
})