當前位置: 首頁>>代碼示例>>Golang>>正文


Golang wefttest.Request類代碼示例

本文整理匯總了Golang中github.com/GeoNet/weft/wefttest.Request的典型用法代碼示例。如果您正苦於以下問題:Golang Request類的具體用法?Golang Request怎麽用?Golang Request使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Request類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestTagAll

// all tags as a protobuf
func TestTagAll(t *testing.T) {
	setup(t)
	defer teardown()

	// Load test data.
	if err := routes.DoAllStatusOk(testServer.URL); err != nil {
		t.Error(err)
	}

	r := wt.Request{ID: wt.L(), URL: "/tag", Accept: "application/x-protobuf"}

	var b []byte
	var err error

	if b, err = r.Do(testServer.URL); err != nil {
		t.Error(err)
	}

	var tr mtrpb.TagResult

	if err = proto.Unmarshal(b, &tr); err != nil {
		t.Error(err)
	}

	if len(tr.Result) != 6 {
		t.Errorf("expected 6 tags got %d", len(tr.Result))
	}

	if tr.Result[0].Tag != "DAGG" {
		t.Errorf("expected DAGG as the first tag got %s", tr.Result[0].Tag)
	}
}
開發者ID:GeoNet,項目名稱:mtr,代碼行數:33,代碼來源:routes_test.go

示例2: TestTag

// protobuf of field metrics and latencies for a single tag.
func TestTag(t *testing.T) {
	setup(t)
	defer teardown()

	// Load test data.
	if err := routes.DoAllStatusOk(testServer.URL); err != nil {
		t.Error(err)
	}

	r := wt.Request{ID: wt.L(), URL: "/tag/TAUP", Accept: "application/x-protobuf"}

	var b []byte
	var err error

	if b, err = r.Do(testServer.URL); err != nil {
		t.Error(err)
	}

	var tr mtrpb.TagSearchResult

	if err = proto.Unmarshal(b, &tr); err != nil {
		t.Error(err)
	}

	if tr.FieldMetric == nil {
		t.Error("Got nil FieldMetric")
	}

	if tr.DataLatency == nil {
		t.Error("Got nil DataLatency")
	}

	if tr.FieldState == nil {
		t.Error("Got nil FieldState")
	}

	if tr.DataCompleteness == nil {
		t.Error("Got nil DataCompleteness")
	}

	if tr.FieldMetric[0].DeviceID != "gps-taupoairport" {
		t.Errorf("expected deviceID gps-taupoairport got %s", tr.FieldMetric[0].DeviceID)
	}

	if tr.DataLatency[0].SiteID != "TAUP" {
		t.Errorf("expected siteID TAUP got %s", tr.DataLatency[0].SiteID)
	}

	if tr.FieldState[0].DeviceID != "gps-taupoairport" {
		t.Errorf("expected deviceID gps-taupoairport got %s", tr.FieldState[0].DeviceID)
	}

	if tr.DataCompleteness[0].SiteID != "TAUP" {
		t.Errorf("expected siteID TAUP got %s", tr.DataCompleteness[0].SiteID)
	}
}
開發者ID:GeoNet,項目名稱:mtr,代碼行數:57,代碼來源:routes_test.go

示例3: TestFieldMetricsThreshold

// protobuf of field metric threshold info.
func TestFieldMetricsThreshold(t *testing.T) {
	setup(t)
	defer teardown()

	// Load test data.
	if err := routes.DoAllStatusOk(testServer.URL); err != nil {
		t.Error(err)
	}

	r := wt.Request{ID: wt.L(), URL: "/field/metric/threshold", Accept: "application/x-protobuf"}

	var b []byte
	var err error

	if b, err = r.Do(testServer.URL); err != nil {
		t.Error(err)
	}

	var f mtrpb.FieldMetricThresholdResult

	if err = proto.Unmarshal(b, &f); err != nil {
		t.Error(err)
	}

	if f.Result == nil {
		t.Error("got nil for /field/metric/threshold protobuf")
	}

	if len(f.Result) != 1 {
		t.Error("expected 1 result.")
	}

	d := f.Result[0]

	if d.DeviceID != "gps-taupoairport" {
		t.Errorf("expected gps-taupoairport got %s", d.DeviceID)
	}

	if d.TypeID != "voltage" {
		t.Errorf("expected voltage got %s", d.TypeID)
	}

	if d.Upper != 45000 {
		t.Errorf("expected 45000 got %d", d.Upper)
	}

	if d.Lower != 12000 {
		t.Errorf("expected 12000 got %d", d.Lower)
	}

	if d.Scale != 0.001 {
		t.Errorf("expected 0.001 got %f", d.Scale)
	}
}
開發者ID:GeoNet,項目名稱:mtr,代碼行數:55,代碼來源:routes_test.go

示例4: TestDataSites

// protobuf of data sites.
func TestDataSites(t *testing.T) {
	setup(t)
	defer teardown()

	// Load test data.
	if err := routes.DoAllStatusOk(testServer.URL); err != nil {
		t.Error(err)
	}

	r := wt.Request{ID: wt.L(), URL: "/data/site", Accept: "application/x-protobuf"}

	var b []byte
	var err error

	if b, err = r.Do(testServer.URL); err != nil {
		t.Error(err)
	}

	var f mtrpb.DataSiteResult

	if err = proto.Unmarshal(b, &f); err != nil {
		t.Error(err)
	}

	if f.Result == nil {
		t.Error("got nil for /data/site protobuf")
	}

	if len(f.Result) != 2 {
		t.Error("expected 2 results.")
	}

	var found bool

	for _, v := range f.Result {
		if v.SiteID == "TAUP" {
			found = true

			if v.Latitude != -38.74270 {
				t.Errorf("Data site TAUP got expected latitude -38.74270 got %f", v.Latitude)
			}

			if v.Longitude != 176.08100 {
				t.Errorf("Data site TAUP got expected longitude 176.08100 got %f", v.Longitude)
			}
		}
	}

	if !found {
		t.Error("Didn't find site TAUP")
	}
}
開發者ID:GeoNet,項目名稱:mtr,代碼行數:53,代碼來源:routes_test.go

示例5: TestFieldState

// protobuf for /field/state endpoint
func TestFieldState(t *testing.T) {
	setup(t)
	defer teardown()

	// Load test data.
	if err := routes.DoAllStatusOk(testServer.URL); err != nil {
		t.Error(err)
	}

	r := wt.Request{ID: wt.L(), URL: "/field/state", Accept: "application/x-protobuf"}

	var b []byte
	var err error

	// get the protobuf data back
	if b, err = r.Do(testServer.URL); err != nil {
		t.Fatal(err)
	}

	var dtr mtrpb.FieldStateResult

	if err = proto.Unmarshal(b, &dtr); err != nil {
		t.Fatal(err)
	}

	if dtr.Result == nil {
		t.Fatal("got nil for /field/state protobuf")
	}

	if len(dtr.Result) != 1 {
		t.Fatalf("expected 1 result, got %d.", len(dtr.Result))
	}

	res := dtr.Result[0]

	if res.DeviceID != "gps-taupoairport" {
		t.Errorf("expected gps-taupoairport got %s", res.DeviceID)
	}

	if res.TypeID != "mains" {
		t.Errorf("expected mains got %s", res.TypeID)
	}

	if res.Seconds != 1431639630 {
		t.Errorf("expected 1431639630 got %d", res.Seconds)
	}

	if res.Value != true {
		t.Errorf("expected true got %s", res.Value)
	}
}
開發者ID:GeoNet,項目名稱:mtr,代碼行數:52,代碼來源:routes_test.go

示例6: TestFieldDevice

// protobuf of /model/device endpoint
func TestFieldDevice(t *testing.T) {
	setup(t)
	defer teardown()

	// Load test data.
	if err := routes.DoAllStatusOk(testServer.URL); err != nil {
		t.Error(err)
	}

	r := wt.Request{ID: wt.L(), URL: "/field/device", Accept: "application/x-protobuf"}

	var b []byte
	var err error

	if b, err = r.Do(testServer.URL); err != nil {
		t.Error(err)
	}

	var fdr mtrpb.FieldDeviceResult

	if err = proto.Unmarshal(b, &fdr); err != nil {
		t.Error(err)
	}

	// ftr.Result should be a slice of struct pointers
	if fdr.Result == nil {
		t.Error("got nil for /field/device protobuf")
	}

	if len(fdr.Result) != 1 {
		t.Error("expected 1 result.")
	}

	d := fdr.Result[0]

	if d.ModelID != "Trimble NetR9" {
		t.Errorf("expected Trimble NetR9 got %s", d.ModelID)
	}

	if d.DeviceID != "gps-taupoairport" {
		t.Errorf("expected gps-taupoairport got %s", d.DeviceID)
	}

	if d.Latitude != -38.7427 {
		t.Errorf("expected -38.7427 got %s", d.Latitude)
	}

	if d.Longitude != 176.081 {
		t.Errorf("expected 176.081 got %s", d.Longitude)
	}
}
開發者ID:GeoNet,項目名稱:mtr,代碼行數:52,代碼來源:routes_test.go

示例7: TestFieldStateTag

// protobuf for /field/state/tag endpoint
func TestFieldStateTag(t *testing.T) {
	setup(t)
	defer teardown()

	// Load test data.
	if err := routes.DoAllStatusOk(testServer.URL); err != nil {
		t.Error(err)
	}

	r := wt.Request{ID: wt.L(), URL: "/field/state/tag", Method: "GET", Accept: "application/x-protobuf"}

	var b []byte
	var err error

	// get the protobuf data back
	if b, err = r.Do(testServer.URL); err != nil {
		t.Fatal(err)
	}

	var tr mtrpb.FieldStateTagResult

	if err = proto.Unmarshal(b, &tr); err != nil {
		t.Fatal(err)
	}

	if tr.Result == nil {
		t.Fatal("got nil for /field/state protobuf")
	}

	if len(tr.Result) != 1 {
		t.Fatalf("expected 1 result, got %d.", len(tr.Result))
	}

	res := tr.Result[0]

	if res.DeviceID != "gps-taupoairport" {
		t.Errorf("expected gps-taupoairport got %s", res.DeviceID)
	}

	if res.TypeID != "mains" {
		t.Errorf("expected mains got %s", res.TypeID)
	}

	if res.Tag != "TAUP" {
		t.Errorf("expected TAUP got %s", res.Tag)
	}
}
開發者ID:GeoNet,項目名稱:mtr,代碼行數:48,代碼來源:routes_test.go

示例8: TestFieldMetricHistoryLog

// protobuf of metric history log info.
func TestFieldMetricHistoryLog(t *testing.T) {
	setup(t)
	defer teardown()

	// Load test data.
	if err := routes.DoAllStatusOk(testServer.URL); err != nil {
		t.Error(err)
	}

	r := wt.Request{ID: wt.L(), URL: "/field/metric?deviceID=gps-taupoairport&typeID=voltage&resolution=minute", Accept: "application/x-protobuf"}

	var b []byte
	var err error

	if b, err = r.Do(testServer.URL); err != nil {
		t.Error(err)
	}

	var f mtrpb.FieldMetricResult

	if err = proto.Unmarshal(b, &f); err != nil {
		t.Error(err)
	}

	if f.DeviceID != "gps-taupoairport" {
		t.Errorf("expected gps-taupoairport got %s", f.DeviceID)
	}

	if f.TypeID != "voltage" {
		t.Errorf("expected voltage got %s", f.TypeID)
	}

	if f.Upper != 45000 {
		t.Errorf("expected 45000 got %d", f.Upper)
	}

	if f.Lower != 12000 {
		t.Errorf("expected 12000 got %d", f.Lower)
	}

	if f.Scale != 0.001 {
		t.Errorf("expected 12000 got %f", f.Scale)
	}

	// Not testing number of latency log
}
開發者ID:GeoNet,項目名稱:mtr,代碼行數:47,代碼來源:routes_test.go

示例9: TestDataLatencyHistoryLog

// protobuf of latency history log info.
func TestDataLatencyHistoryLog(t *testing.T) {
	setup(t)
	defer teardown()

	// Load test data.
	if err := routes.DoAllStatusOk(testServer.URL); err != nil {
		t.Error(err)
	}

	r := wt.Request{ID: wt.L(), URL: "/data/latency?siteID=TAUP&typeID=latency.strong&resolution=minute", Accept: "application/x-protobuf"}

	var b []byte
	var err error

	if b, err = r.Do(testServer.URL); err != nil {
		t.Error(err)
	}

	var f mtrpb.DataLatencyResult

	if err = proto.Unmarshal(b, &f); err != nil {
		t.Error(err)
	}

	if f.SiteID != "TAUP" {
		t.Errorf("expected TAUP got %s", f.SiteID)
	}

	if f.TypeID != "latency.strong" {
		t.Errorf("expected latency.strong got %s", f.TypeID)
	}

	if f.Upper != 15000 {
		t.Errorf("expected 15000 got %d", f.Upper)
	}

	if f.Lower != 12000 {
		t.Errorf("expected 12000 got %d", f.Lower)
	}

	if f.Scale != 1.0 {
		t.Errorf("expected 1.0 got %f", f.Scale)
	}
	// Not testing number of latency log
}
開發者ID:GeoNet,項目名稱:mtr,代碼行數:46,代碼來源:routes_test.go

示例10: TestQuakesCount

func TestQuakesCount(t *testing.T) {
	setup(t)
	defer teardown()
	//1. get all quakes
	r := wt.Request{
		Accept: CONTENT_TYPE_JSON,
		URL:    "/count?bbox=163.60840,-49.18170,182.98828,-32.28713",
	}
	b, err := r.Do(ts.URL)
	if err != nil {
		t.Error(err)
		t.Error(string(b))
	}
	var qc QuakesCount
	err = json.Unmarshal(b, &qc)
	if err != nil {
		log.Fatal(err)
	}
	if qc.Count != 3 {
		t.Errorf("Found wrong number of quakes: %d", qc.Count)
	}

	//2. get only one quake
	r = wt.Request{
		Accept: CONTENT_TYPE_JSON,
		URL:    "/count?bbox=163.60840,-49.18170,182.98828,-32.28713&startdate=2010-1-1T00:00:00&enddate=2015-1-1T00:00:00",
	}
	b, err = r.Do(ts.URL)
	if err != nil {
		t.Error(err)
		t.Error(string(b))
	}

	err = json.Unmarshal(b, &qc)
	if err != nil {
		t.Error(err)
	}
	if qc.Count != 1 {
		t.Errorf("Found wrong number of quakes: %d", qc.Count)
	}

	//3. get 2 quakes
	r = wt.Request{
		Accept: CONTENT_TYPE_JSON,
		URL:    "/count?bbox=163.60840,-49.18170,182.98828,-32.28713&minmag=5",
	}
	b, err = r.Do(ts.URL)
	if err != nil {
		t.Error(err)
		t.Error(string(b))
	}

	err = json.Unmarshal(b, &qc)
	if err != nil {
		t.Error(err)
	}
	if qc.Count != 2 {
		t.Errorf("Found wrong number of quakes: %d", qc.Count)
	}
}
開發者ID:GeoNet,項目名稱:haz,代碼行數:60,代碼來源:quakes_test.go

示例11: TestQuakesGeoJson

func TestQuakesGeoJson(t *testing.T) {
	setup(t)
	defer teardown()
	//1. get all quakes
	r := wt.Request{URL: "/geojson?limit=100&bbox=163.60840,-49.18170,182.98828,-32.28713", Accept: CONTENT_TYPE_GeoJSON}

	b, err := r.Do(ts.URL)
	if err != nil {
		t.Error(err)
		t.Error(string(b))
	}

	var f GeoJsonFeatureCollection
	err = json.Unmarshal(b, &f)
	if err != nil {
		log.Fatal(err)
	}
	if len(f.Features) != 3 {
		t.Errorf("Found wrong number of features: %d", len(f.Features))
	}

	//2. get only one quake
	r = wt.Request{URL: "/geojson?limit=100&bbox=163.60840,-49.18170,182.98828,-32.28713&startdate=2010-1-1T00:00:00&enddate=2015-1-1T00:00:00", Accept: CONTENT_TYPE_GeoJSON}

	b, err = r.Do(ts.URL)
	if err != nil {
		t.Error(err)
		t.Error(string(b))
	}

	err = json.Unmarshal(b, &f)
	if err != nil {
		log.Fatal(err)
	}
	if len(f.Features) != 1 {
		t.Errorf("Found wrong number of features: %d", len(f.Features))
	}
	if f.Features[0].Properties.Publicid != "3366146" {
		t.Errorf("Found wrong publicid: %s", f.Features[0].Properties.Publicid)
	}

}
開發者ID:GeoNet,項目名稱:haz,代碼行數:42,代碼來源:quakes_test.go

示例12: TestFieldType

// protobuf of /model/type endpoint
func TestFieldType(t *testing.T) {
	setup(t)
	defer teardown()

	// Load test data.
	if err := routes.DoAllStatusOk(testServer.URL); err != nil {
		t.Error(err)
	}

	r := wt.Request{ID: wt.L(), URL: "/field/type", Accept: "application/x-protobuf"}

	var b []byte
	var err error

	if b, err = r.Do(testServer.URL); err != nil {
		t.Error(err)
	}

	var ftr mtrpb.FieldTypeResult

	if err = proto.Unmarshal(b, &ftr); err != nil {
		t.Error(err)
	}

	// ftr.Result should be a slice of struct pointers
	if ftr.Result == nil {
		t.Error("got nil for /field/type protobuf")
	}

	if len(ftr.Result) != 12 {
		t.Error("expected 12 results.")
	}

	if ftr.Result[0].TypeID != "centre" {
		t.Errorf("expected centre got %s", ftr.Result[0].TypeID)
	}

	if ftr.Result[0].Display != "mV" {
		t.Errorf("expected mV got %s", ftr.Result[0].Display)
	}
}
開發者ID:GeoNet,項目名稱:mtr,代碼行數:42,代碼來源:routes_test.go

示例13: TestGeoJSONFormat

func TestGeoJSONFormat(t *testing.T) {
	setup(t)
	defer teardown()

	r := wt.Request{
		ID:      wt.L(),
		Accept:  CONTENT_TYPE_GeoJSON,
		Content: CONTENT_TYPE_GeoJSON,
		URL:     "/geojson?limit=100&bbox=163.60840,-49.18170,182.98828,-32.28713&startdate=2000-1-1T00:00:00&enddate=2015-1-1T00:00:00",
	}

	b, err := r.Do(ts.URL)
	if err != nil {
		t.Error(err)
		t.Error(string(b))
	}
	body := bytes.NewBuffer(b)

	res, err := client.Post("http://geojsonlint.com/validate", "application/vnd.geo+json", body)
	defer res.Body.Close()
	if err != nil {
		t.Errorf("Problem contacting geojsonlint for test %s", r.ID)
	}

	b, err = ioutil.ReadAll(res.Body)
	if err != nil {
		t.Errorf("Problem reading body from geojsonlint for test %s", r.ID)
	}

	var v valid

	err = json.Unmarshal(b, &v)
	if err != nil {
		t.Errorf("Problem unmarshalling body from geojsonlint for test %s", r.ID)
	}

	if v.Status != "ok" {
		t.Errorf("invalid geoJSON for test %s" + r.ID)
	}
}
開發者ID:GeoNet,項目名稱:haz,代碼行數:40,代碼來源:quakes_test.go

示例14: TestDataTypes

func TestDataTypes(t *testing.T) {
	setup(t)
	defer teardown()

	// Load test data.
	if err := routes.DoAllStatusOk(testServer.URL); err != nil {
		t.Error(err)
	}

	r := wt.Request{ID: wt.L(), URL: "/data/type", Accept: "application/x-protobuf"}

	var b []byte
	var err error

	if b, err = r.Do(testServer.URL); err != nil {
		t.Error(err)
	}

	var dtr mtrpb.DataTypeResult

	if err = proto.Unmarshal(b, &dtr); err != nil {
		t.Error(err)
	}

	if dtr.Result == nil {
		t.Error("got nil for /data/type protobuf")
	}

	if len(dtr.Result) != 5 {
		t.Errorf("expected 5 results, got %d.", len(dtr.Result))
	}

	if dtr.Result[0].TypeID != "latency.files.gnss" {
		t.Errorf("expected latency.files.gnss got %s", dtr.Result[0].TypeID)
	}

	if dtr.Result[0].Display != "ms" {
		t.Errorf("expected ms got %s", dtr.Result[0].Display)
	}
}
開發者ID:GeoNet,項目名稱:mtr,代碼行數:40,代碼來源:routes_test.go

示例15: TestFieldModel

// protobuf of /field/model endpoint
func TestFieldModel(t *testing.T) {
	setup(t)
	defer teardown()

	// Load test data.
	if err := routes.DoAllStatusOk(testServer.URL); err != nil {
		t.Error(err)
	}

	r := wt.Request{ID: wt.L(), URL: "/field/model", Accept: "application/x-protobuf"}

	var b []byte
	var err error

	if b, err = r.Do(testServer.URL); err != nil {
		t.Error(err)
	}

	var ftr mtrpb.FieldModelResult

	if err = proto.Unmarshal(b, &ftr); err != nil {
		t.Error(err)
	}

	// ftr.Result should be a slice of struct pointers
	if ftr.Result == nil {
		t.Error("got nil for /field/model protobuf")
	}

	if len(ftr.Result) != 1 {
		t.Error("expected 1 result.")
	}

	m := ftr.Result[0]

	if m.ModelID != "Trimble NetR9" {
		t.Errorf("expected Trimble NetR9 got %s", m.ModelID)
	}
}
開發者ID:GeoNet,項目名稱:mtr,代碼行數:40,代碼來源:routes_test.go


注:本文中的github.com/GeoNet/weft/wefttest.Request類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。