appengine icon indicating copy to clipboard operation
appengine copied to clipboard

unsupported protocol scheme "" for aetest.NewInstance.NewRequest tests

Open mattes opened this issue 7 years ago • 2 comments

package main

import (
	"net/http"
	"testing"

	"google.golang.org/appengine/aetest"
)

func TestSomething(t *testing.T) {
	inst, err := aetest.NewInstance(nil)
	if err != nil {
		t.Fatalf("Failed to create instance: %v", err)
	}
	defer inst.Close()

	req, err := inst.NewRequest("GET", "/", nil)
	if err != nil {
		t.Fatalf("Failed to create req1: %v", err)
	}

	_, err = http.DefaultClient.Do(req)
	if err != nil {
		t.Fatal(err)
	}
}

(more or less copied from https://cloud.google.com/appengine/docs/standard/go/tools/localunittesting/)

returns:

go test
INFO     2018-08-16 05:22:23,401 devappserver2.py:120] Skipping SDK update check.
WARNING  2018-08-16 05:22:23,401 devappserver2.py:136] DEFAULT_VERSION_HOSTNAME will not be set correctly with --port=0
WARNING  2018-08-16 05:22:23,483 simple_search_stub.py:1196] Could not read search indexes from /var/folders/nc/k5t3z35d6kg9c20_7y2p6w800000gn/T/appengine.testapp.matthias/search_indexes
INFO     2018-08-16 05:22:23,487 api_server.py:274] Starting API server at: http://localhost:56620
INFO     2018-08-16 05:22:23,494 dispatcher.py:270] Starting module "default" running at: http://localhost:56621
INFO     2018-08-16 05:22:23,497 admin_server.py:152] Starting admin server at: http://localhost:56622
--- FAIL: TestSomething (4.29s)
        main_test.go:30: Get /: unsupported protocol scheme ""
FAIL
exit status 1
FAIL    github.com/xxxx/xxx 4.316s

mattes avatar Aug 16 '18 05:08 mattes

As a work-around, I'm now using:

func TestSomethingElse(t *testing.T) {
	ctx, done, err := aetest.NewContext()
	if err != nil {
		t.Fatal(err)
	}
	defer done()

	r := httptest.NewRequest("GET", "/", nil)

	r = r.WithContext(ctx)

	w := httptest.NewRecorder()

	indexHandler(w, r)
}

... where indexHandler is a http.HandlerFunc

mattes avatar Aug 16 '18 05:08 mattes

I should notice, I'm testing with go test. Maybe I need to use goapp test?

ref: https://github.com/golang/appengine/issues/115

mattes avatar Aug 16 '18 05:08 mattes