https://github.com/goapt/test
golang unit testing tools
https://github.com/goapt/test
Last synced: 10 months ago
JSON representation
golang unit testing tools
- Host: GitHub
- URL: https://github.com/goapt/test
- Owner: goapt
- License: mit
- Created: 2020-08-19T04:05:15.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2021-07-09T08:57:39.000Z (almost 5 years ago)
- Last Synced: 2025-03-26T10:16:00.574Z (about 1 year ago)
- Language: Go
- Size: 39.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
## Golang unit testing tools
```go
go get github.com/goapt/test
```
### HTTP Mock
```go
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](https://github.com/alicebob/miniredis)
```go
rds := test.NewRedis()
```
### Gee handler test
```go
req := test.NewRequest("/test", func(c *gee.Context) gee.Response {
return c.String("ok")
})
```