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

Golang aetesting.FakeSingleContext函数代码示例

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

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



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

示例1: TestGetPresenceMultiInvalid

func TestGetPresenceMultiInvalid(t *testing.T) {
	c := aetesting.FakeSingleContext(t, "xmpp", "BulkGetPresence", func(in *pb.BulkPresenceRequest, out *pb.BulkPresenceResponse) error {
		if !reflect.DeepEqual(in.Jid, []string{"[email protected]", "[email protected]"}) {
			return fmt.Errorf("bad request jids %#v", in.Jid)
		}
		out.PresenceResponse = []*pb.PresenceResponse{
			newPresenceResponse(true, pb.PresenceResponse_EXTENDED_AWAY, true),
			newPresenceResponse(true, pb.PresenceResponse_CHAT, false),
		}
		return nil
	})

	jids := []string{"[email protected]", "[email protected]"}
	presence, err := GetPresenceMulti(c, jids, "")

	wantErr := appengine.MultiError{nil, ErrInvalidJID}
	if !reflect.DeepEqual(err, wantErr) {
		t.Fatalf("GetPresenceMulti: got %#v, want %#v", err, wantErr)
	}

	want := []string{"xa", ""}
	if !reflect.DeepEqual(presence, want) {
		t.Errorf("GetPresenceMulti: got %#v, want %#v", presence, want)
	}
}
开发者ID:kleopatra999,项目名称:appengine,代码行数:25,代码来源:xmpp_test.go


示例2: TestGetRequest

func TestGetRequest(t *testing.T) {
	serviceCalled := false
	apiKey := "lyric"

	c := aetesting.FakeSingleContext(t, "memcache", "Get", func(req *pb.MemcacheGetRequest, _ *pb.MemcacheGetResponse) error {
		// Test request.
		if n := len(req.Key); n != 1 {
			t.Errorf("got %d want 1", n)
			return nil
		}
		if k := string(req.Key[0]); k != apiKey {
			t.Errorf("got %q want %q", k, apiKey)
		}

		serviceCalled = true
		return nil
	})

	// Test the "forward" path from the API call parameters to the
	// protobuf request object. (The "backward" path from the
	// protobuf response object to the API call response,
	// including the error response, are handled in the next few
	// tests).
	Get(c, apiKey)
	if !serviceCalled {
		t.Error("Service was not called as expected")
	}
}
开发者ID:Celluliodio,项目名称:flannel,代码行数:28,代码来源:memcache_test.go


示例3: TestGetPresenceMultiFromJID

func TestGetPresenceMultiFromJID(t *testing.T) {
	c := aetesting.FakeSingleContext(t, "xmpp", "BulkGetPresence", func(in *pb.BulkPresenceRequest, out *pb.BulkPresenceResponse) error {
		if !reflect.DeepEqual(in.Jid, []string{"[email protected]", "[email protected]"}) {
			return fmt.Errorf("bad request jids %#v", in.Jid)
		}
		if jid := in.GetFromJid(); jid != "[email protected]" {
			return fmt.Errorf("bad from jid %q", jid)
		}
		out.PresenceResponse = []*pb.PresenceResponse{
			newPresenceResponse(true, pb.PresenceResponse_NORMAL, true),
			newPresenceResponse(true, pb.PresenceResponse_CHAT, true),
		}
		return nil
	})

	jids := []string{"[email protected]", "[email protected]"}
	presence, err := GetPresenceMulti(c, jids, "[email protected]")
	if err != nil {
		t.Fatalf("GetPresenceMulti: %v", err)
	}
	want := []string{"", "chat"}
	if !reflect.DeepEqual(presence, want) {
		t.Errorf("GetPresenceMulti: got %v, want %v", presence, want)
	}
}
开发者ID:kleopatra999,项目名称:appengine,代码行数:25,代码来源:xmpp_test.go


示例4: TestNamespaceResetting

func TestNamespaceResetting(t *testing.T) {
	namec := make(chan *string, 1)
	c0 := aetesting.FakeSingleContext(t, "memcache", "Get", func(req *pb.MemcacheGetRequest, res *pb.MemcacheGetResponse) error {
		namec <- req.NameSpace
		return errRPC
	})

	// Check that wrapping c0 in a namespace twice works correctly.
	c1, err := appengine.Namespace(c0, "A")
	if err != nil {
		t.Fatalf("appengine.Namespace: %v", err)
	}
	c2, err := appengine.Namespace(c1, "") // should act as the original context
	if err != nil {
		t.Fatalf("appengine.Namespace: %v", err)
	}

	Get(c0, "key")
	if ns := <-namec; ns != nil {
		t.Errorf(`Get with c0: ns = %q, want nil`, *ns)
	}

	Get(c1, "key")
	if ns := <-namec; ns == nil {
		t.Error(`Get with c1: ns = nil, want "A"`)
	} else if *ns != "A" {
		t.Errorf(`Get with c1: ns = %q, want "A"`, *ns)
	}

	Get(c2, "key")
	if ns := <-namec; ns != nil {
		t.Errorf(`Get with c2: ns = %q, want nil`, *ns)
	}
}
开发者ID:trythings,项目名称:trythings,代码行数:34,代码来源:memcache_test.go


示例5: TestNamespaceResetting

func TestNamespaceResetting(t *testing.T) {
	var nsField *string
	c := aetesting.FakeSingleContext(t, "memcache", "Get", func(req *pb.MemcacheGetRequest, res *pb.MemcacheGetResponse) error {
		nsField = req.NameSpace
		return errRPC
	})

	// Check that wrapping c in a namespace twice works correctly.
	nc, err := appengine.Namespace(c, "A")
	if err != nil {
		t.Fatalf("appengine.Namespace: %v", err)
	}
	c0, err := appengine.Namespace(nc, "") // should act as the original context
	if err != nil {
		t.Fatalf("appengine.Namespace: %v", err)
	}

	Get(c, "key")
	if nsField != nil {
		t.Fatalf("Get with c yielded %q", *nsField)
	}
	Get(nc, "key")
	if nsField == nil || *nsField != "A" {
		t.Fatalf("Get with nc yielded %v", nsField)
	}
	Get(c0, "key")
	if nsField != nil && *nsField != "" {
		t.Fatalf("Get with c0 yielded %q", *nsField)
	}
}
开发者ID:Celluliodio,项目名称:flannel,代码行数:30,代码来源:memcache_test.go


示例6: TestAddRequest

func TestAddRequest(t *testing.T) {
	var apiItem = &Item{
		Key:   "lyric",
		Value: []byte("Oh, give me a home"),
	}

	serviceCalled := false

	c := aetesting.FakeSingleContext(t, "memcache", "Set", func(req *pb.MemcacheSetRequest, _ *pb.MemcacheSetResponse) error {
		// Test request.
		pbItem := req.Item[0]
		if k := string(pbItem.Key); k != apiItem.Key {
			t.Errorf("got %q want %q", k, apiItem.Key)
		}
		if v := string(apiItem.Value); v != string(pbItem.Value) {
			t.Errorf("got %q want %q", v, string(pbItem.Value))
		}
		if p := *pbItem.SetPolicy; p != pb.MemcacheSetRequest_ADD {
			t.Errorf("got %v want %v", p, pb.MemcacheSetRequest_ADD)
		}

		serviceCalled = true
		return nil
	})

	Add(c, apiItem)
	if !serviceCalled {
		t.Error("Service was not called as expected")
	}
}
开发者ID:Celluliodio,项目名称:flannel,代码行数:30,代码来源:memcache_test.go


示例7: TestNamespaceResetting

func TestNamespaceResetting(t *testing.T) {
	// These environment variables are necessary because *Query.Run will
	// call internal.FullyQualifiedAppID which checks these variables or falls
	// back to the Metadata service that is not available in tests.
	environ := []struct {
		key, value string
	}{
		{"GAE_LONG_APP_ID", "my-app-id"},
		{"GAE_PARTITION", "1"},
	}
	for _, v := range environ {
		old := os.Getenv(v.key)
		os.Setenv(v.key, v.value)
		v.value = old
	}
	defer func() { // Restore old environment after the test completes.
		for _, v := range environ {
			if v.value == "" {
				os.Unsetenv(v.key)
				continue
			}
			os.Setenv(v.key, v.value)
		}
	}()

	namec := make(chan *string, 1)
	c0 := aetesting.FakeSingleContext(t, "datastore_v3", "RunQuery", func(req *pb.Query, res *pb.QueryResult) error {
		namec <- req.NameSpace
		return fmt.Errorf("RPC error")
	})

	// Check that wrapping c0 in a namespace twice works correctly.
	c1, err := appengine.Namespace(c0, "A")
	if err != nil {
		t.Fatalf("appengine.Namespace: %v", err)
	}
	c2, err := appengine.Namespace(c1, "") // should act as the original context
	if err != nil {
		t.Fatalf("appengine.Namespace: %v", err)
	}

	q := NewQuery("SomeKind")

	q.Run(c0)
	if ns := <-namec; ns != nil {
		t.Errorf(`RunQuery with c0: ns = %q, want nil`, *ns)
	}

	q.Run(c1)
	if ns := <-namec; ns == nil {
		t.Error(`RunQuery with c1: ns = nil, want "A"`)
	} else if *ns != "A" {
		t.Errorf(`RunQuery with c1: ns = %q, want "A"`, *ns)
	}

	q.Run(c2)
	if ns := <-namec; ns != nil {
		t.Errorf(`RunQuery with c2: ns = %q, want nil`, *ns)
	}
}
开发者ID:trythings,项目名称:trythings,代码行数:60,代码来源:datastore_test.go


示例8: TestSetRequest

func TestSetRequest(t *testing.T) {
	var apiItem = &Item{
		Key:   "lyric",
		Value: []byte("Where the buffalo roam"),
	}

	serviceCalled := false

	c := aetesting.FakeSingleContext(t, "memcache", "Set", func(req *pb.MemcacheSetRequest, _ *pb.MemcacheSetResponse) error {
		// Test request.
		if n := len(req.Item); n != 1 {
			t.Errorf("got %d want 1", n)
			return nil
		}
		pbItem := req.Item[0]
		if k := string(pbItem.Key); k != apiItem.Key {
			t.Errorf("got %q want %q", k, apiItem.Key)
		}
		if v := string(pbItem.Value); v != string(apiItem.Value) {
			t.Errorf("got %q want %q", v, string(apiItem.Value))
		}
		if p := *pbItem.SetPolicy; p != pb.MemcacheSetRequest_SET {
			t.Errorf("got %v want %v", p, pb.MemcacheSetRequest_SET)
		}

		serviceCalled = true
		return nil
	})

	Set(c, apiItem)
	if !serviceCalled {
		t.Error("Service was not called as expected")
	}
}
开发者ID:Celluliodio,项目名称:flannel,代码行数:34,代码来源:memcache_test.go


示例9: TestPutAutoOrderID

func TestPutAutoOrderID(t *testing.T) {
	index, err := Open("Doc")
	if err != nil {
		t.Fatalf("err from Open: %v", err)
	}

	c := aetesting.FakeSingleContext(t, "search", "IndexDocument", func(in *pb.IndexDocumentRequest, out *pb.IndexDocumentResponse) error {
		if len(in.Params.GetDocument()) < 1 {
			return fmt.Errorf("expected at least one Document, got %v", in)
		}
		got, want := in.Params.Document[0].GetOrderId(), int32(time.Since(orderIDEpoch).Seconds())
		if d := got - want; -5 > d || d > 5 {
			return fmt.Errorf("got OrderId %d, want near %d", got, want)
		}
		*out = pb.IndexDocumentResponse{
			Status: []*pb.RequestStatus{
				{Code: pb.SearchServiceError_OK.Enum()},
			},
			DocId: []string{
				"doc_id",
			},
		}
		return nil
	})

	if _, err := index.Put(c, "", &searchFields); err != nil {
		t.Fatal(err)
	}
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:29,代码来源:search_test.go


示例10: TestGetPresenceMultiUnavailable

func TestGetPresenceMultiUnavailable(t *testing.T) {
	c := aetesting.FakeSingleContext(t, "xmpp", "BulkGetPresence", func(in *pb.BulkPresenceRequest, out *pb.BulkPresenceResponse) error {
		if !reflect.DeepEqual(in.Jid, []string{"[email protected]", "[email protected]"}) {
			return fmt.Errorf("bad request jids %#v", in.Jid)
		}
		out.PresenceResponse = []*pb.PresenceResponse{
			newPresenceResponse(false, pb.PresenceResponse_AWAY, true),
			newPresenceResponse(false, pb.PresenceResponse_DO_NOT_DISTURB, true),
		}
		return nil
	})

	jids := []string{"[email protected]", "[email protected]"}
	presence, err := GetPresenceMulti(c, jids, "")

	wantErr := appengine.MultiError{
		ErrPresenceUnavailable,
		ErrPresenceUnavailable,
	}
	if !reflect.DeepEqual(err, wantErr) {
		t.Fatalf("GetPresenceMulti: got %#v, want %#v", err, wantErr)
	}
	want := []string{"", ""}
	if !reflect.DeepEqual(presence, want) {
		t.Errorf("GetPresenceMulti: got %#v, want %#v", presence, want)
	}
}
开发者ID:kleopatra999,项目名称:appengine,代码行数:27,代码来源:xmpp_test.go


示例11: TestFieldSpec

func TestFieldSpec(t *testing.T) {
	index, err := Open("Doc")
	if err != nil {
		t.Fatalf("err from Open: %v", err)
	}

	errFoo := errors.New("foo") // sentinel error when there isn't one.

	testCases := []struct {
		desc string
		opts *SearchOptions
		want *pb.FieldSpec
	}{
		{
			desc: "No options",
			want: &pb.FieldSpec{},
		},
		{
			desc: "Fields",
			opts: &SearchOptions{
				Fields: []string{"one", "two"},
			},
			want: &pb.FieldSpec{
				Name: []string{"one", "two"},
			},
		},
		{
			desc: "Expressions",
			opts: &SearchOptions{
				Expressions: []FieldExpression{
					{Name: "one", Expr: "price * quantity"},
					{Name: "two", Expr: "min(daily_use, 10) * rate"},
				},
			},
			want: &pb.FieldSpec{
				Expression: []*pb.FieldSpec_Expression{
					{Name: proto.String("one"), Expression: proto.String("price * quantity")},
					{Name: proto.String("two"), Expression: proto.String("min(daily_use, 10) * rate")},
				},
			},
		},
	}

	for _, tt := range testCases {
		c := aetesting.FakeSingleContext(t, "search", "Search", func(req *pb.SearchRequest, _ *pb.SearchResponse) error {
			params := req.Params
			if !reflect.DeepEqual(params.FieldSpec, tt.want) {
				t.Errorf("%s: params.FieldSpec=%v; want %v", tt.desc, params.FieldSpec, tt.want)
			}
			return errFoo // Always return some error to prevent response parsing.
		})

		it := index.Search(c, "gopher", tt.opts)
		if _, err := it.Next(nil); err != errFoo {
			t.Fatalf("%s: got error %v; want %v", tt.desc, err, errFoo)
		}
	}
}
开发者ID:hortonworks,项目名称:kubernetes-yarn,代码行数:58,代码来源:search_test.go


示例12: TestAddResponseRPCError

func TestAddResponseRPCError(t *testing.T) {
	c := aetesting.FakeSingleContext(t, "memcache", "Set", func(_ *pb.MemcacheSetRequest, res *pb.MemcacheSetResponse) error {
		return errRPC
	})

	if err := Add(c, &Item{}); err != errRPC {
		t.Errorf("got %v want errRPC", err)
	}
}
开发者ID:Celluliodio,项目名称:flannel,代码行数:9,代码来源:memcache_test.go


示例13: TestGetResponseRPCError

func TestGetResponseRPCError(t *testing.T) {
	c := aetesting.FakeSingleContext(t, "memcache", "Get", func(_ *pb.MemcacheGetRequest, res *pb.MemcacheGetResponse) error {
		return errRPC
	})

	if _, err := Get(c, "something"); err != errRPC {
		t.Errorf("got %v want errRPC", err)
	}
}
开发者ID:Celluliodio,项目名称:flannel,代码行数:9,代码来源:memcache_test.go


示例14: TestAddResponseNotStored

func TestAddResponseNotStored(t *testing.T) {
	c := aetesting.FakeSingleContext(t, "memcache", "Set", func(_ *pb.MemcacheSetRequest, res *pb.MemcacheSetResponse) error {
		res.SetStatus = []pb.MemcacheSetResponse_SetStatusCode{pb.MemcacheSetResponse_NOT_STORED}
		return nil
	})

	if err := Add(c, &Item{}); err != ErrNotStored {
		t.Errorf("got %v want ErrNotStored", err)
	}
}
开发者ID:Celluliodio,项目名称:flannel,代码行数:10,代码来源:memcache_test.go


示例15: TestGetResponseMiss

func TestGetResponseMiss(t *testing.T) {
	c := aetesting.FakeSingleContext(t, "memcache", "Get", func(_ *pb.MemcacheGetRequest, res *pb.MemcacheGetResponse) error {
		// don't fill in any of the response
		return nil
	})
	_, err := Get(c, "something")
	if err != ErrCacheMiss {
		t.Errorf("got %v want ErrCacheMiss", err)
	}
}
开发者ID:Celluliodio,项目名称:flannel,代码行数:10,代码来源:memcache_test.go


示例16: TestSetResponseError

func TestSetResponseError(t *testing.T) {
	c := aetesting.FakeSingleContext(t, "memcache", "Set", func(_ *pb.MemcacheSetRequest, res *pb.MemcacheSetResponse) error {
		res.SetStatus = []pb.MemcacheSetResponse_SetStatusCode{pb.MemcacheSetResponse_ERROR}
		return nil
	})

	if err := Set(c, &Item{}); err != ErrServerError {
		t.Errorf("got %v want ErrServerError", err)
	}
}
开发者ID:Celluliodio,项目名称:flannel,代码行数:10,代码来源:memcache_test.go


示例17: TestAddWithEmptyPath

func TestAddWithEmptyPath(t *testing.T) {
	c := aetesting.FakeSingleContext(t, "taskqueue", "Add", func(req *pb.TaskQueueAddRequest, res *pb.TaskQueueAddResponse) error {
		if got, want := string(req.Url), "/_ah/queue/a-queue"; got != want {
			return fmt.Errorf("req.Url = %q; want %q", got, want)
		}
		return nil
	})
	if _, err := Add(c, &Task{}, "a-queue"); err != nil {
		t.Fatalf("Add: %v", err)
	}
}
开发者ID:Celluliodio,项目名称:flannel,代码行数:11,代码来源:taskqueue_test.go


示例18: TestList

func TestList(t *testing.T) {
	c := aetesting.FakeSingleContext(t, "modules", "GetModules", func(req *pb.GetModulesRequest, res *pb.GetModulesResponse) error {
		res.Module = []string{"default", "mod1"}
		return nil
	})
	got, err := List(c)
	if err != nil {
		t.Fatalf("List: %v", err)
	}
	want := []string{"default", "mod1"}
	if !reflect.DeepEqual(got, want) {
		t.Errorf("List = %v, want %v", got, want)
	}
}
开发者ID:Celluliodio,项目名称:flannel,代码行数:14,代码来源:module_test.go


示例19: TestGetMultiEmpty

func TestGetMultiEmpty(t *testing.T) {
	serviceCalled := false
	c := aetesting.FakeSingleContext(t, "memcache", "Get", func(req *pb.MemcacheGetRequest, _ *pb.MemcacheGetResponse) error {
		serviceCalled = true
		return nil
	})

	// Test that the Memcache service is not called when
	// GetMulti is passed an empty slice of keys.
	GetMulti(c, []string{})
	if serviceCalled {
		t.Error("Service was called but should not have been")
	}
}
开发者ID:Celluliodio,项目名称:flannel,代码行数:14,代码来源:memcache_test.go


示例20: TestMessageConstruction

func TestMessageConstruction(t *testing.T) {
	var got *pb.MailMessage
	c := aetesting.FakeSingleContext(t, "mail", "Send", func(in *pb.MailMessage, out *basepb.VoidProto) error {
		got = in
		return nil
	})

	msg := &Message{
		Sender: "[email protected]",
		To:     []string{"[email protected]"},
		Body:   "Hey, lunch time?",
		Attachments: []Attachment{
			// Regression test for a prod bug. The address of a range variable was used when
			// constructing the outgoing proto, so multiple attachments used the same name.
			{
				Name:      "att1.txt",
				Data:      []byte("data1"),
				ContentID: "<att1>",
			},
			{
				Name: "att2.txt",
				Data: []byte("data2"),
			},
		},
	}
	if err := Send(c, msg); err != nil {
		t.Fatalf("Send: %v", err)
	}
	want := &pb.MailMessage{
		Sender:   proto.String("[email protected]"),
		To:       []string{"[email protected]"},
		Subject:  proto.String(""),
		TextBody: proto.String("Hey, lunch time?"),
		Attachment: []*pb.MailAttachment{
			{
				FileName:  proto.String("att1.txt"),
				Data:      []byte("data1"),
				ContentID: proto.String("<att1>"),
			},
			{
				FileName: proto.String("att2.txt"),
				Data:     []byte("data2"),
			},
		},
	}
	if !proto.Equal(got, want) {
		t.Errorf("Bad proto for %+v\n got %v\nwant %v", msg, got, want)
	}
}
开发者ID:kleopatra999,项目名称:appengine,代码行数:49,代码来源:mail_test.go



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Golang datastore.Property类代码示例发布时间:2022-05-28
下一篇:
Golang internal.RegisterErrorCodeMap函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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