abide icon indicating copy to clipboard operation
abide copied to clipboard

Cache test results

Open rafaeljusto opened this issue 7 years ago • 1 comments

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 avatar Jan 07 '19 16:01 rafaeljusto

Hey @sjkaliski , do you see any solution for the above? It would be great to speed-up the tests.

rafaeljusto avatar May 01 '20 12:05 rafaeljusto