Exemplo n.º 1
0
func TestFlexibleResponseWriter(t *testing.T) {
	t.Parallel()
	u := mock.NewRequestHandler(nil)

	testHandler(t, u, "/test/", mock.DefaultRequestHandlerResponse, mock.DefaultRequestHandlerResponseCode)
	testHandler(t, u, "/error/", mock.DefaultRequestHandlerResponse, mock.DefaultRequestHandlerResponseCode)

	u.Handle("/error/", http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
		w.WriteHeader(400)
		fmt.Fprintf(w, "Error")
	}))
	testHandler(t, u, "/error/", "Error", 400)
}
Exemplo n.º 2
0
func newTestAppFromMap(t testing.TB, fsmap map[string]string) *testApp {
	up := mock.NewRequestHandler(fsMapHandler(fsmap))
	cpus := runtime.NumCPU()
	runtime.GOMAXPROCS(cpus)
	loc := &types.Location{}
	var err error
	loc.Logger = newStdLogger()
	loc.CacheKey = "test"
	loc.CacheKeyIncludesQuery = false

	path, cleanup := testutils.GetTestFolder(t)

	cz := &config.CacheZone{
		ID:             "1",
		Type:           "disk",
		Path:           path,
		StorageObjects: 200,
		Algorithm:      "lru",
		PartSize:       5,
	}

	st, err := storage.New(cz, loc.Logger)
	if err != nil {
		panic(err)
	}
	ca, err := cache.New(cz, st.DiscardPart, loc.Logger)
	if err != nil {
		panic(err)
	}
	loc.Cache = &types.CacheZone{
		ID:        cz.ID,
		PartSize:  cz.PartSize,
		Algorithm: ca,
		Scheduler: storage.NewScheduler(),
		Storage:   st,
	}

	cacheHandler, err := New(nil, loc, up)
	if err != nil {
		t.Fatal(err)
	}
	app := &testApp{
		TB:           t,
		up:           up,
		ctx:          context.Background(),
		cacheHandler: cacheHandler,
		fsmap:        fsmap,
		cleanup:      cleanup,
	}
	return app
}