Cache test results
rafaeljusto opened this issue · 1 comments
rafaeljusto commented
Because abide library always write the snapshot file here when calling abide.Cleanup()
the tests are never cached. Do we need to save those snapshots every time in the cleanup?
abidecache.go
package abidecache
import (
"encoding/json"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
data := map[string]string{
"foo": "bar",
}
body, err := json.Marshal(data)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.Write(body)
}
abidecache_test.go
package abidecache
import (
"net/http/httptest"
"os"
"testing"
"github.com/beme/abide"
)
func TestMain(m *testing.M) {
exit := m.Run()
abide.Cleanup()
os.Exit(exit)
}
func TestRequests(t *testing.T) {
req := httptest.NewRequest("GET", "http://example.com/", nil)
w := httptest.NewRecorder()
handler(w, req)
res := w.Result()
abide.AssertHTTPResponse(t, "first route", res)
}
Running (snapshots already updated)
➜ go test ./...
ok labs/abidecache 0.018s
➜ go test ./...
ok labs/abidecache 0.022s
Running (abide.Cleanup commented)
➜ go test ./...
ok labs/abidecache 0.018s
➜ go test ./...
ok labs/abidecache (cached)
rafaeljusto commented
Hey @sjkaliski , do you see any solution for the above? It would be great to speed-up the tests.