コード例 #1
0
ファイル: api-v1_test.go プロジェクト: jasonish/dumpy
func TestApiV1TestDownloadValid(t *testing.T) {
	env := env.New()
	mockProxyCreator := MockProxyDumpCreator{}
	env.ProxyCreator = &mockProxyCreator

	// Create an emtpy spool to be used as the default.
	env.Config.Spools = []*config.SpoolConfig{
		&config.SpoolConfig{},
	}

	// endTime and duration not allowed together.
	request := &http.Request{
		Method: "GET",
		URL:    &url.URL{Path: "/api/v1/download"},
		Form: url.Values{
			"startTime": {"0"},
			"duration":  {"1s"},
		},
	}

	rr := httptest.NewRecorder()
	err := apiV1RequestWrapper(env, rr, request, ApiV1DownloadRequestHandler)
	test.FailIf(t, err != nil)
	proxy := mockProxyCreator.GetProxy()
	test.FailIfNot(t, proxy.didRun)
	test.FailIf(t, proxy.options.StartTime != 0)
	test.FailIf(t, proxy.options.Duration != 1)
}
コード例 #2
0
ファイル: api-v1_test.go プロジェクト: jasonish/dumpy
// Test that if endTime and duration are provided that we fail the request.
func TestApiV1DownloadRequestHandler(t *testing.T) {
	env := env.New()
	env.ProxyCreator = &MockProxyDumpCreator{}

	// endTime and duration not allowed together.
	request := &http.Request{
		Method: "GET",
		URL:    &url.URL{Path: "/api/v1/download"},
		Form: url.Values{
			"endTime":  {"1"},
			"duration": {"1s"},
		},
	}

	rr := httptest.NewRecorder()
	err := apiV1RequestWrapper(env, rr, request, ApiV1DownloadRequestHandler)
	if err == nil {
		t.Fatal("err should not be nil")
	}
	if err.Code != http.StatusBadRequest {
		t.Fatal("unexpected error code")
	}

}