Talk about golden files
This commit is contained in:
parent
2d46cb0487
commit
e49db490a8
1 changed files with 18 additions and 0 deletions
|
@ -500,3 +500,21 @@ Good example
|
||||||
* httptest
|
* httptest
|
||||||
|
|
||||||
.play httptest/main.go /func/,/^}/
|
.play httptest/main.go /func/,/^}/
|
||||||
|
|
||||||
|
* golden files
|
||||||
|
|
||||||
|
func TestExample(t *testing.T) {
|
||||||
|
recorder := httptest.NewRecorder()
|
||||||
|
|
||||||
|
req, err := http.NewRequest("GET", "/example", nil)
|
||||||
|
assert.Nil(t, err)
|
||||||
|
|
||||||
|
handler := http.HandlerFunc(ExampleHandler)
|
||||||
|
handler.ServeHTTP()
|
||||||
|
|
||||||
|
g := goldie.New(t)
|
||||||
|
g.Assert(t, "example", recorder.Body.Bytes())
|
||||||
|
}
|
||||||
|
|
||||||
|
* `go test -update` сохраняет результат в файл
|
||||||
|
* `go test` сравнивает вывод с сохранённым результатом
|
Loading…
Reference in a new issue