예제 #1
0
func TestParamsDeserializeWithMissingParams(t *testing.T) {
	p := necessaryParams()

	_, err := parseHandleFromParams(p)
	gt.AssertNil(t, err)

	p.Del("hStamp")
	_, err = parseHandleFromParams(p)
	gt.AssertNotNil(t, err)

	p = necessaryParams()
	p.Del("h1")
	_, err = parseHandleFromParams(p)
	gt.AssertNotNil(t, err)

	p = necessaryParams()
	p.Del("h2")
	_, err = parseHandleFromParams(p)
	gt.AssertNotNil(t, err)

	p = necessaryParams()
	p.Del("h3")
	_, err = parseHandleFromParams(p)
	gt.AssertNotNil(t, err)
}
예제 #2
0
func TestAsyncTaskCreation(t *testing.T) {
	q := &MockTaskQueue{}
	cfg := &Environment{taskQueue: q}
	s := "lllat=1.0&lllng=2.0&urlat%3d3.0&urlng=4.0&start=5&end=6"
	u := "http://myhost.com/async_drawmap/?code=vercode&state=" + url.QueryEscape(s)

	res := execute(t, u, AsyncDrawMapHandler, cfg)

	gt.AssertEqualM(t, http.StatusFound, res.StatusCode,
		"Should redirect. Body: "+res.Body)
	// TODO(mrjones): verify URL better.
	//	gt.AssertEqualM(t, "/display/100-1-2-3.png", res.Headers.Get("Location"),
	//		"Should redirect to specified URL")

	gt.AssertEqualM(t, "/drawmap_worker", q.lastUrl, "Should enqueue a drawmap worker")
	rawS := q.lastParams.Get("state")
	rawS, err := url.QueryUnescape(rawS)
	gt.AssertNil(t, err)
	parsedS, err := url.ParseQuery(rawS)

	gt.AssertEqualM(t, "1.0000000000000000", parsedS.Get("lllat"), "token")
	gt.AssertEqualM(t, "2.0000000000000000", parsedS.Get("lllng"), "token")
	gt.AssertEqualM(t, "3.0000000000000000", parsedS.Get("urlat"), "token")
	gt.AssertEqualM(t, "4.0000000000000000", parsedS.Get("urlng"), "token")
	gt.AssertEqualM(t, "5", parsedS.Get("start"), "token")
	gt.AssertEqualM(t, "6", parsedS.Get("end"), "token")
	gt.AssertEqualM(t, "vercode", q.lastParams.Get("verification_code"), "code")
	//	gt.AssertEqualM(t, "abc", q.lastParams.Get("access_token"), "token")
	//	gt.AssertEqualM(t, "def", q.lastParams.Get("refresh_token"), "token")
}
예제 #3
0
func setUpFakeBlobStore(t *testing.T) (string, BlobStore) {
	dir := randomDirectoryName()
	err := os.Mkdir(dir, 0755)
	gt.AssertNil(t, err)

	blobStore := NewLocalFSBlobStore(dir)
	return dir, blobStore
}
예제 #4
0
func TestSuccessfulUrlSerializesAndDeserialize(t *testing.T) {
	h := simpleHandle()

	url := serializeHandleToUrl(h, "suffix", "page")
	h2, err := parseHandleFromUrl(url)

	gt.AssertNil(t, err)
	gt.AssertEqualM(t, h, h2, "Expected serialize/deserialize to return the same result.")
}
예제 #5
0
func TestSuccessfulParamsSerializeAndDeserialize(t *testing.T) {
	h := simpleHandle()

	var p = make(url.Values)

	serializeHandleToParams(h, &p)
	h2, err := parseHandleFromParams(&p)

	gt.AssertNil(t, err)
	gt.AssertEqualM(t, h, h2, "Should be equal")
}
예제 #6
0
func TestSquareBox(t *testing.T) {
	box, err := NewBoundingBox(
		Coordinate{Lat: 0, Lng: 0},
		Coordinate{Lat: 10, Lng: 10})
	gt.AssertNil(t, err)

	w, h := imgSize(box, 500)

	gt.AssertEqualM(t, 500, w, "Width should be maxed for a square box")
	gt.AssertEqualM(t, 500, h, "Height should be maxed for a square box")
}
예제 #7
0
func TestTallBox(t *testing.T) {
	box, err := NewBoundingBox(
		Coordinate{Lat: 0, Lng: 0},
		Coordinate{Lat: 10, Lng: 5})
	gt.AssertNil(t, err)

	w, h := imgSize(box, 500)

	gt.AssertEqualM(t, 250, w, "Width should be narrow for a tall box")
	gt.AssertEqualM(t, 500, h, "Height should be maxed for a tall box")
}
예제 #8
0
func TestContainsAround0Latitude(t *testing.T) {
	b, err := NewBoundingBox(
		Coordinate{Lat: -1.0, Lng: 1.0},
		Coordinate{Lat: 1.0, Lng: 2.0})

	gt.AssertNil(t, err)

	gt.AssertTrueM(t, b.Contains(&Coordinate{Lat: 0, Lng: 1.5}), "In Box")

	gt.AssertFalseM(t, b.Contains(&Coordinate{Lat: -1.5, Lng: 1.5}), "East")
	gt.AssertFalseM(t, b.Contains(&Coordinate{Lat: 2.5, Lng: 1.5}), "West")
}
예제 #9
0
func TestContainsBoundaries(t *testing.T) {
	b, err := NewBoundingBox(
		Coordinate{Lat: -1.0, Lng: -1.0},
		Coordinate{Lat: 1.0, Lng: 1.0})

	gt.AssertNil(t, err)

	gt.AssertFalseM(t, b.Contains(&Coordinate{Lat: -1, Lng: 0}), "South")
	gt.AssertFalseM(t, b.Contains(&Coordinate{Lat: 1, Lng: 0}), "North")
	gt.AssertFalseM(t, b.Contains(&Coordinate{Lat: 0, Lng: -1}), "East")
	gt.AssertFalseM(t, b.Contains(&Coordinate{Lat: 0, Lng: 1}), "West")
}
예제 #10
0
func TestContainsAround180Longitude(t *testing.T) {
	b, err := NewBoundingBox(
		Coordinate{Lat: 1.0, Lng: 179.0},
		Coordinate{Lat: 2.0, Lng: -179.0})

	gt.AssertNil(t, err)

	gt.AssertTrueM(t, b.Contains(&Coordinate{Lat: 1.5, Lng: -179.9}), "In Box (E)")
	gt.AssertTrueM(t, b.Contains(&Coordinate{Lat: 1.5, Lng: 179.9}), "In Box (W)")

	gt.AssertFalseM(t, b.Contains(&Coordinate{Lat: 1.5, Lng: 178}), "East")
	gt.AssertFalseM(t, b.Contains(&Coordinate{Lat: 1.5, Lng: -178}), "West")
}
예제 #11
0
func TestContainsSE(t *testing.T) {
	b, err := NewBoundingBox(
		Coordinate{Lat: 1.0, Lng: -2.0},
		Coordinate{Lat: 2.0, Lng: -1.0})

	gt.AssertNil(t, err)

	gt.AssertTrueM(t, b.Contains(&Coordinate{Lat: 1.5, Lng: -1.5}), "In Box")

	gt.AssertFalseM(t, b.Contains(&Coordinate{Lat: 0.5, Lng: -1.5}), "East")
	gt.AssertFalseM(t, b.Contains(&Coordinate{Lat: 2.5, Lng: -1.5}), "West")
	gt.AssertFalseM(t, b.Contains(&Coordinate{Lat: 1.5, Lng: -2.5}), "South")
	gt.AssertFalseM(t, b.Contains(&Coordinate{Lat: 1.5, Lng: -0.5}), "North")
}
예제 #12
0
func execute(t *testing.T,
	url string,
	handler func(http.ResponseWriter, *http.Request),
	env *Environment) *FakeResponse {
	UseEnvironmentFactory(NewStaticEnvironmentFactory(env))

	req, err := http.NewRequest("GET", url, nil)
	gt.AssertNil(t, err)

	res := NewFakeResponse()
	handler(res, req)

	return res
}
예제 #13
0
func TestWidthAround180(t *testing.T) {
	b, err := NewBoundingBox(
		Coordinate{Lat: 1.0, Lng: 179.0},
		Coordinate{Lat: 10.0, Lng: -179.0})

	gt.AssertNil(t, err)
	if b.Width() != 2.0 {
		t.Fatalf("Wrong width: Expected 2.0, Actual: %f", b.Width())
	}
	wf := b.WidthFraction(&Coordinate{Lat: 1.0, Lng: 179.5})
	if wf != 0.25 {
		t.Fatalf("Wrong width fraction: Expected .25, Actual: %f", wf)
	}
	wf = b.WidthFraction(&Coordinate{Lat: 1.0, Lng: -179.5})
	if wf != 0.75 {
		t.Fatalf("Wrong width fraction: Expected .75, Actual: %f", wf)
	}
}
예제 #14
0
func TestObjectReady(t *testing.T) {
	dir, blobStore := setUpFakeBlobStore(t)
	defer os.RemoveAll(dir)

	cfg := NewEnvironment(blobStore, nil, nil, nil)

	res1 := execute(t, "http://myhost.com/is_ready/100-1-2-3.png", IsReadyHandler, cfg)
	gt.AssertEqualM(t, http.StatusOK, res1.StatusCode, "Request should have succeeded")
	gt.AssertEqualM(t, "fail", res1.Body, "Should not have found the object")

	h := &Handle{n1: 1, n2: 2, n3: 3, timestamp: 100}
	err := blobStore.Store(h, &Blob{})
	gt.AssertNil(t, err)

	res2 := execute(t, "http://myhost.com/is_ready/100-1-2-3.png", IsReadyHandler, cfg)
	gt.AssertEqualM(t, http.StatusOK, res2.StatusCode, "Request should have succeeded")
	gt.AssertEqualM(t, "ok", res2.Body, "Should have found the object this time.")
}
예제 #15
0
func TestBwPngVisualizerNotSquare(t *testing.T) {
	bounds, err := NewBoundingBox(
		Coordinate{Lat: 0, Lng: 0},
		Coordinate{Lat: 3, Lng: 5})
	gt.AssertNil(t, err)

	h := make(History, 0)
	h = append(h, &Coordinate{Lat: .5, Lng: .5})
	h = append(h, &Coordinate{Lat: 1.5, Lng: 1.5})
	h = append(h, &Coordinate{Lat: 2.5, Lng: 2.5})
	h = append(h, &Coordinate{Lat: 1.5, Lng: 3.5})
	h = append(h, &Coordinate{Lat: .5, Lng: 4.5})

	visualizer := &BwPngVisualizer{}

	img := visualizer.makeImage(&h, bounds, 5, 3)
	assertImage(t, [][]color.Color{
		[]color.Color{W, W, B, W, W},
		[]color.Color{W, B, W, B, W},
		[]color.Color{B, W, W, W, B}}, img)
}
예제 #16
0
func TestBwPngVisualizerSmushed(t *testing.T) {
	bounds, err := NewBoundingBox(
		Coordinate{Lat: 0, Lng: 0},
		Coordinate{Lat: 50, Lng: 50})
	gt.AssertNil(t, err)

	h := make(History, 0)
	// Lots of points, but they're all in the lower left.
	h = append(h, &Coordinate{Lat: 1, Lng: 1})
	h = append(h, &Coordinate{Lat: 2, Lng: 2})
	h = append(h, &Coordinate{Lat: 3, Lng: 3})
	h = append(h, &Coordinate{Lat: 4, Lng: 4})
	h = append(h, &Coordinate{Lat: 5, Lng: 5})

	visualizer := &BwPngVisualizer{}

	img := visualizer.makeImage(&h, bounds, 2, 2)
	assertImage(t, [][]color.Color{
		[]color.Color{W, W},
		[]color.Color{B, W}}, img)

}
예제 #17
0
func TestBwPngVisualizer2By2(t *testing.T) {
	bounds, err := NewBoundingBox(
		Coordinate{Lat: 0, Lng: 0},
		Coordinate{Lat: 2, Lng: 2})
	gt.AssertNil(t, err)

	h := make(History, 0)
	h = append(h, &Coordinate{Lat: .5, Lng: .5})

	visualizer := &BwPngVisualizer{}
	img := visualizer.makeImage(&h, bounds, 2, 2)
	assertImage(t, [][]color.Color{
		[]color.Color{W, W},
		[]color.Color{B, W}}, img)

	h = append(h, &Coordinate{Lat: 1.5, Lng: 1.5})

	img = visualizer.makeImage(&h, bounds, 2, 2)
	assertImage(t, [][]color.Color{
		[]color.Color{W, B},
		[]color.Color{B, W}}, img)
}
예제 #18
0
func TestNormalWidth(t *testing.T) {
	b, err := NewBoundingBox(
		Coordinate{Lat: 1.0, Lng: 1.0},
		Coordinate{Lat: 10.0, Lng: 2.0})

	gt.AssertNil(t, err)
	if b.Width() != 1.0 {
		t.Fatal("Wrong width: Expected 1.0, Actual: %f", b.Width())
	}
	wf := b.WidthFraction(&Coordinate{Lat: 1.0, Lng: 1.5})
	if wf != 0.5 {
		t.Fatal("Wrong width fraction: Expected .5, Actual: %f", wf)
	}
	wf = b.WidthFraction(&Coordinate{Lat: 1.0, Lng: 1.25})
	if wf != 0.25 {
		t.Fatal("Wrong width fraction: Expected .25, Actual: %f", wf)
	}

	if b.Height() != 9.0 {
		t.Fatal("Wrong height: Expected 9.0, Actual: %f", b.Height())
	}

}