Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache test results #51

Open
rafaeljusto opened this issue Jan 7, 2019 · 1 comment
Open

Cache test results #51

rafaeljusto opened this issue Jan 7, 2019 · 1 comment

Comments

@rafaeljusto
Copy link
Contributor

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
Copy link
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant