Ejemplo n.º 1
0
func TestParseWithPartialRequest(t *testing.T) {
	res := dh.RequestResource{}

	jsonString := `{ "url": "http://example.com/some/resource" }`
	incomingJson := strings.NewReader(jsonString)

	expectedIncoming := api.IncomingRequest{URL: "http://example.com/some/resource"}

	r, _ := res.DecodeInputRequest(incomingJson)
	if *r != expectedIncoming {
		t.Errorf(`DecodeInputRequest('%s') = %q want %q`, jsonString, r, expectedIncoming)
	}
}
Ejemplo n.º 2
0
func TestParseCompleteRequest(t *testing.T) {
	res := dh.RequestResource{}

	jsonString := `{ "url": "http://example.com/some/resource", "checksum": "abcde", "checksum_type": "abc", "callback": "http://example.com/callback" }`
	incomingJson := strings.NewReader(jsonString)

	expectedIncoming := api.IncomingRequest{
		URL:          "http://example.com/some/resource",
		Checksum:     "abcde",
		ChecksumType: "abc",
		Callback:     "http://example.com/callback"}

	r, _ := res.DecodeInputRequest(incomingJson)
	if *r != expectedIncoming {
		t.Errorf(`DecodeInputRequest('%s') = %q want %q`, jsonString, r, expectedIncoming)
	}
}
Ejemplo n.º 3
0
func TestGetRequestURL(t *testing.T) {
	requestID := "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"

	expectedURL, _ := url.Parse("/aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee")
	res := dh.RequestResource{}
	router := mux.NewRouter()

	res.RegisterRoutes(router)

	u, err := res.GetRequestURL(requestID)

	if err != nil {
		t.Error(err)
	}

	if *u != *expectedURL {
		t.Errorf(`GetRequestURL('%s') = %q want %q`, requestID, u, expectedURL)
	}
}