• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Golang testutil.SystemTest函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/GoogleCloudPlatform/golang-samples/internal/testutil.SystemTest函数的典型用法代码示例。如果您正苦于以下问题:Golang SystemTest函数的具体用法?Golang SystemTest怎么用?Golang SystemTest使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了SystemTest函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: TestList

func TestList(t *testing.T) {
	t.Skip("Flaky. Eventual consistency. Re-enable once the datastore emulator works with gRPC.")

	testutil.SystemTest(t)
	ctx := context.Background()

	desc := makeDesc()

	k, err := AddTask(ctx, client, desc)
	if err != nil {
		t.Fatal(err)
	}

	foundTask := listAndGetTask(t, desc)
	if got, want := foundTask.id, k.ID; got != want {
		t.Errorf("k.ID: got %d, want %d", got, want)
	}

	if err := MarkDone(ctx, client, foundTask.id); err != nil {
		t.Fatal(err)
	}

	foundTask = listAndGetTask(t, desc)
	if !foundTask.Done {
		t.Error("foundTask.Done: got false, want true")
	}

	if err := DeleteTask(ctx, client, foundTask.id); err != nil {
		t.Fatal(err)
	}
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:31,代码来源:tasks_test.go


示例2: TestCustomMetric

func TestCustomMetric(t *testing.T) {
	hc := testutil.SystemTest(t)
	ctx, _ := context.WithTimeout(context.Background(), time.Second*30)

	s, err := createService(ctx)
	if err != nil {
		t.Fatal(err)
	}

	if err := createCustomMetric(s, hc.ProjectID, metricType); err != nil {
		t.Fatal(err)
	}

	for {
		_, err = getCustomMetric(s, hc.ProjectID, metricType)
		if err == nil {
			break
		}
		time.Sleep(2 * time.Second)
	}
	if err != nil {
		t.Fatal(err)
	}

	time.Sleep(2 * time.Second)

	if err := writeTimeSeriesValue(s, hc.ProjectID, metricType); err != nil {
		t.Error(err)
	}

	if err := readTimeSeriesValue(s, hc.ProjectID, metricType); err != nil {
		t.Error(err)
	}
}
开发者ID:jeffmendoza,项目名称:golang-samples,代码行数:34,代码来源:custommetric_test.go


示例3: TestCreate

func TestCreate(t *testing.T) {
	tc := testutil.SystemTest(t)
	c := setup(t)
	if err := create(c, tc.ProjectID, bucketName); err != nil {
		t.Fatalf("failed to create bucket (%q): %v", bucketName, err)
	}
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:7,代码来源:main_test.go


示例4: TestRecognize

func TestRecognize(t *testing.T) {
	testutil.SystemTest(t)

	ctx := context.Background()
	client, err := speech.NewClient(ctx)
	if err != nil {
		t.Fatal(err)
	}

	opName, err := send(client, "./quit.raw")
	if err != nil {
		t.Fatal(err)
	}
	if opName == "" {
		t.Fatal("got no op name; want one")
	}
	resp, err := wait(client, opName)
	if err != nil {
		t.Fatal(err)
	}
	if len(resp.Results) == 0 {
		t.Fatal("got no results; want at least one")
	}
	result := resp.Results[0]
	if len(result.Alternatives) < 1 {
		t.Fatal("got no alternatives; want at least one")
	}
	if got, want := result.Alternatives[0].Transcript, "quit"; got != want {
		t.Errorf("Transcript: got %q; want %q", got, want)
	}
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:31,代码来源:captionasync_test.go


示例5: TestSimplelog

func TestSimplelog(t *testing.T) {
	tc := testutil.SystemTest(t)
	ctx := context.Background()

	client, err := logging.NewClient(ctx, tc.ProjectID)
	if err != nil {
		t.Fatalf("logging.NewClient: %v", err)
	}
	adminClient, err := logadmin.NewClient(ctx, tc.ProjectID)
	if err != nil {
		t.Fatalf("logadmin.NewClient: %v", err)
	}
	defer func() {
		if err := client.Close(); err != nil {
			t.Errorf("Close: %v", err)
		}
	}()

	defer func() {
		testutil.Retry(t, 10, time.Second, func(r *testutil.R) {
			if err := deleteLog(adminClient); err != nil {
				r.Errorf("deleteLog: %v", err)
			}
		})
	}()

	client.OnError = func(err error) {
		t.Errorf("OnError: %v", err)
	}

	writeEntry(client)
	structuredWrite(client)

	testutil.Retry(t, 10, time.Second, func(r *testutil.R) {
		entries, err := getEntries(adminClient, tc.ProjectID)
		if err != nil {
			r.Errorf("getEntries: %v", err)
			return
		}

		if got, want := len(entries), 2; got != want {
			r.Errorf("len(entries) = %d; want %d", got, want)
			return
		}

		wantContain := map[string]*logging.Entry{
			"Anything":                            entries[0],
			"The payload can be any type!":        entries[0],
			"infolog is a standard Go log.Logger": entries[1],
		}

		for want, entry := range wantContain {
			msg := fmt.Sprintf("%s", entry.Payload)
			if !strings.Contains(msg, want) {
				r.Errorf("want %q to contain %q", msg, want)
			}
		}
	})
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:59,代码来源:simplelog_test.go


示例6: TestDelete

func TestDelete(t *testing.T) {
	testutil.SystemTest(t)

	c := setup(t)
	if err := delete(c, bucketName); err != nil {
		t.Fatalf("failed to delete bucket (%q): %v", bucketName, err)
	}
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:8,代码来源:main_test.go


示例7: TestListInstances

func TestListInstances(t *testing.T) {
	tc := testutil.SystemTest(t)

	// Just check the call succeeds.
	_, err := ListInstances(tc.ProjectID)
	if err != nil {
		t.Fatal(err)
	}
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:9,代码来源:listinstances_test.go


示例8: setup

func setup(t *testing.T) *pubsub.Client {
	ctx := context.Background()
	tc := testutil.SystemTest(t)

	client, err := pubsub.NewClient(ctx, tc.ProjectID)
	if err != nil {
		t.Fatalf("failed to create client: %v", err)
	}
	return client
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:10,代码来源:main_test.go


示例9: TestListBuckets

func TestListBuckets(t *testing.T) {
	tc := testutil.SystemTest(t)

	buckets, err := ListBuckets(tc.ProjectID)
	if err != nil {
		t.Errorf("error while listing buckets: %s", err)
	}
	if len(buckets) <= 0 {
		t.Error("want non-empty list of buckets")
	}
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:11,代码来源:listbuckets_test.go


示例10: TestCreateWithAttrs

func TestCreateWithAttrs(t *testing.T) {
	tc := testutil.SystemTest(t)
	c := setup(t)
	name := bucketName + "-attrs"
	if err := createWithAttrs(c, tc.ProjectID, name); err != nil {
		t.Fatalf("failed to create bucket (%q): %v", bucketName, err)
	}
	if err := delete(c, name); err != nil {
		t.Fatalf("failed to delete bucket (%q): %v", bucketName, err)
	}
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:11,代码来源:main_test.go


示例11: TestListSupported

func TestListSupported(t *testing.T) {
	testutil.SystemTest(t)

	buf := &bytes.Buffer{}
	if err := listSupportedLanguages(buf, "th"); err != nil {
		t.Fatal(err)
	}
	if got, want := buf.String(), `"en":`; !strings.Contains(got, want) {
		t.Errorf("listSupportedLanguages(th): want %q in %q", want, got)
	}
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:11,代码来源:snippet_test.go


示例12: TestLabel

func TestLabel(t *testing.T) {
	testutil.SystemTest(t)

	labels, err := findLabels("../testdata/cat.jpg")
	if err != nil {
		t.Fatalf("got %v, want nil err", err)
	}
	if len(labels) == 0 {
		t.Fatalf("want non-empty slice of labels")
	}
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:11,代码来源:label_test.go


示例13: TestTranslateText

func TestTranslateText(t *testing.T) {
	testutil.SystemTest(t)

	got, err := translateText("ja", "The Go Gopher is cute")
	if err != nil {
		t.Fatalf("translateText: %v", err)
	}
	if want := "可愛い"; !strings.Contains(got, want) {
		t.Errorf("translateText(Gophers are cute)=%q; want to contain %q", got, want)
	}
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:11,代码来源:snippet_test.go


示例14: TestListInstances

func TestListInstances(t *testing.T) {
	tc := testutil.SystemTest(t)

	instances, err := ListInstances(tc.ProjectID)
	if err != nil {
		t.Fatal(err)
	}
	if len(instances) == 0 {
		t.Fatalf("want non-zero SQL instances in project %q", tc.ProjectID)
	}
}
开发者ID:jeffmendoza,项目名称:golang-samples,代码行数:11,代码来源:listinstances_test.go


示例15: TestAll

func TestAll(t *testing.T) {
	tc := testutil.SystemTest(t)
	ctx := context.Background()

	client, err := bigquery.NewClient(ctx, tc.ProjectID)
	if err != nil {
		t.Fatal(err)
	}
	datasetID := fmt.Sprintf("golang_example_dataset_%d", time.Now().Unix())
	if err := createDataset(client, datasetID); err != nil {
		t.Errorf("failed to create dataset: %v", err)
	}
	if err := listDatasets(client); err != nil {
		t.Errorf("failed to create dataset: %v", err)
	}

	tableID := fmt.Sprintf("golang_example_table_%d", time.Now().Unix())
	if err := createTable(client, datasetID, tableID); err != nil {
		t.Errorf("failed to create table: %v", err)
	}
	buf := &bytes.Buffer{}
	if err := listTables(client, buf, datasetID); err != nil {
		t.Errorf("failed to list tables: %v", err)
	}
	if got := buf.String(); !strings.Contains(got, tableID) {
		t.Errorf("want table list %q to contain table %q", got, tableID)
	}
	if err := insertRows(client, datasetID, tableID); err != nil {
		t.Errorf("failed to insert rows: %v", err)
	}
	if err := listRows(client, datasetID, tableID); err != nil {
		t.Errorf("failed to list rows: %v", err)
	}
	if err := browseTable(client, datasetID, tableID); err != nil {
		t.Errorf("failed to list rows: %v", err)
	}
	if err := asyncQuery(client, datasetID, tableID); err != nil {
		t.Errorf("failed to async query: %v", err)
	}

	dstTableID := fmt.Sprintf("golang_example_tabledst_%d", time.Now().Unix())
	if err := copyTable(client, datasetID, tableID, dstTableID); err != nil {
		t.Errorf("failed to copy table: %v", err)
	}
	if err := deleteTable(client, datasetID, tableID); err != nil {
		t.Errorf("failed to delete table: %v", err)
	}
	if err := deleteTable(client, datasetID, dstTableID); err != nil {
		t.Errorf("failed to delete table: %v", err)
	}

	deleteDataset(t, ctx, datasetID)
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:53,代码来源:snippet_test.go


示例16: TestSentiment

func TestSentiment(t *testing.T) {
	testutil.SystemTest(t)
	ctx, c := newClient(t)

	res, err := analyzeSentiment(ctx, c, "I am very happy.")
	if err != nil {
		t.Fatalf("got %v, want nil err", err)
	}
	if got := res.DocumentSentiment.Score; got <= 0 {
		t.Errorf("sentiment score: got %f, want positive", got)
	}
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:12,代码来源:analyze_test.go


示例17: TestDetect

func TestDetect(t *testing.T) {
	testutil.SystemTest(t)

	detection, err := detectLanguage("可愛い")
	if err != nil {
		t.Fatalf("detectLanguage: %v", err)
	}

	if got, want := detection.Language, language.Japanese; got != want {
		t.Errorf("detection.Language: got %q; want %q", got, want)
	}
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:12,代码来源:snippet_test.go


示例18: TestImportExport

func TestImportExport(t *testing.T) {
	tc := testutil.SystemTest(t)
	ctx := context.Background()

	client, err := bigquery.NewClient(ctx, tc.ProjectID)
	if err != nil {
		t.Fatal(err)
	}
	storageClient, err := storage.NewClient(ctx)
	if err != nil {
		t.Fatal(err)
	}

	datasetID := fmt.Sprintf("golang_example_dataset_importexport_%d", time.Now().Unix())
	tableID := fmt.Sprintf("golang_example_dataset_importexport_%d", time.Now().Unix())
	if err := createDataset(client, datasetID); err != nil {
		t.Errorf("failed to create dataset: %v", err)
	}
	schema := bigquery.Schema{
		&bigquery.FieldSchema{Name: "Year", Type: bigquery.IntegerFieldType},
		&bigquery.FieldSchema{Name: "City", Type: bigquery.StringFieldType},
	}
	if err := client.Dataset(datasetID).Table(tableID).Create(ctx, schema); err != nil {
		t.Errorf("failed to create dataset: %v", err)
	}
	defer deleteDataset(t, ctx, datasetID)

	if err := importFromFile(client, datasetID, tableID, "testdata/olympics.csv"); err != nil {
		t.Fatalf("failed to import from file: %v", err)
	}

	bucket := fmt.Sprintf("golang-example-bigquery-importexport-bucket-%d", time.Now().Unix())
	const object = "values.csv"

	if err := storageClient.Bucket(bucket).Create(ctx, tc.ProjectID, nil); err != nil {
		t.Fatalf("cannot create bucket: %v", err)
	}

	gcsURI := fmt.Sprintf("gs://%s/%s", bucket, object)
	if err := exportToGCS(client, datasetID, tableID, gcsURI); err != nil {
		t.Errorf("failed to export to %v: %v", gcsURI, err)
	}

	// Cleanup the bucket and object.
	if err := storageClient.Bucket(bucket).Object(object).Delete(ctx); err != nil {
		t.Errorf("failed to cleanup the GCS object: %v", err)
	}
	time.Sleep(time.Second) // Give it a second, due to eventual consistency.
	if err := storageClient.Bucket(bucket).Delete(ctx); err != nil {
		t.Errorf("failed to cleanup the GCS bucket: %v", err)
	}
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:52,代码来源:snippet_test.go


示例19: TestEntity

func TestEntity(t *testing.T) {
	testutil.SystemTest(t)
	ctx, c := newClient(t)

	res, err := analyzeEntities(ctx, c, "Homer Simpson likes donuts.")
	if err != nil {
		t.Fatalf("got %v, want nil err", err)
	}
	for _, e := range res.Entities {
		if e.Name == "Homer Simpson" {
			return // found
		}
	}
	t.Errorf("got %+v; want Homer in Entities", res)
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:15,代码来源:analyze_test.go


示例20: TestQuery

func TestQuery(t *testing.T) {
	tc := testutil.SystemTest(t)

	rows, err := Query(tc.ProjectID, "SELECT corpus FROM publicdata:samples.shakespeare GROUP BY corpus;")
	if err != nil {
		t.Fatal(err)
	}

	for _, row := range rows {
		if row[0] == "romeoandjuliet" {
			return
		}
	}
	t.Errorf("got rows: %q; want romeoandjuliet", rows)
}
开发者ID:GoogleCloudPlatform,项目名称:golang-samples,代码行数:15,代码来源:syncquery_test.go



注:本文中的github.com/GoogleCloudPlatform/golang-samples/internal/testutil.SystemTest函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang app.RunKubelet函数代码示例发布时间:2022-05-23
下一篇:
Golang inode.Inode类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap