当前位置: 首页>>代码示例>>Golang>>正文


Golang mailbox.Create函数代码示例

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


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

示例1: TestPut

func TestPut(t *testing.T) {
	mb1, err := mailbox.Create("put1")
	if err != nil {
		t.Fatal(err)
	}
	mb2, err := mailbox.Create("put2")
	if err != nil {
		t.Fatal(err)
	}
	accessKey := mailbox.AccessKey{FullAccess: true}
	accessKey.Create()
	req := api.PutMessageRequest{
		Mailboxes: []string{
			mb1.Id,
			mb2.Id,
		},
		Body: "TEST",
	}
	req.Sign(accessKey.Name, accessKey.Secret)
	var resp api.PutMessageResponse
	code := doRequest(t, req, &resp, "put")
	count, err := mb1.MessageCount()
	if err != nil {
		t.Fatal(err)
	}
	if count == 0 {
		t.Fatal("Message not added to mailbox")
	}
	count, err = mb2.MessageCount()
	if err != nil {
		t.Fatal(err)
	}
	if count == 0 {
		t.Fatal("Message not added to mailbox")
	}
	if code != 200 {
		t.Fatal("Server responded with", code)
	}
	message1, err := mb1.GetMessage()
	if err != nil {
		t.Fatal(err)
	}
	message2, err := mb2.GetMessage()
	if err != nil {
		t.Fatal(err)
	}
	if message1 == nil || message2 == nil {
		t.Fatal("Message is nil")
	}
	if message1.Body != "TEST" {
		t.Fatal("Incorrect message1 body", message1.Body)
	}
	if message2.Body != "TEST" {
		t.Fatal("Incorrect message2 body", message2.Body)
	}
}
开发者ID:5Sigma,项目名称:Conduit,代码行数:56,代码来源:server_test.go

示例2: TestClientPut

// TestClientPut checks to make sure the client is capable of sending messages
// to a given mailbox.
func TestClientPut(t *testing.T) {
	mb1, _ := mailbox.Create("put1")
	mb2, _ := mailbox.Create("put2")
	_, err := pmClient.Put([]string{mb1.Id, mb2.Id}, "", "PUT TEST", "", "")
	if err != nil {
		t.Fatal(err)
	}
	count1, _ := mb1.MessageCount()
	count2, _ := mb2.MessageCount()
	if count1 != 1 || count2 != 1 {
		t.Fatal("Message counts are ", count1, ",", count2)
	}
}
开发者ID:5Sigma,项目名称:Conduit,代码行数:15,代码来源:client_test.go

示例3: TestRun

func TestRun(t *testing.T) {
	mb, err := mailbox.Create("test.testrun")
	if err != nil {
		t.Fatal(err)
	}
	key := mailbox.AccessKey{MailboxId: mb.Id}
	err = key.Create()
	if err != nil {
		t.Fatal(err)
	}
	msg, err := mb.PutMessage(`$("test");`)
	if err != nil {
		t.Fatal(err)
	}
	viper.Set("host", ":5112")
	viper.Set("mailbox", mb.Id)
	viper.Set("access_key", key.Secret)
	viper.Set("access_key_name", key.Name)
	viper.Set("show_requests", true)
	go serverCmd.Run(serverCmd, []string{})
	runCmd.ParseFlags([]string{"-1", "-d"})
	runCmd.Run(runCmd, []string{})
	dep, _ := mailbox.FindDeployment(msg.Deployment)
	resp, _ := dep.GetResponses()
	if len(resp) != 1 {
		t.Fatal("No response")
	}
}
开发者ID:5Sigma,项目名称:Conduit,代码行数:28,代码来源:run_test.go

示例4: TestResponse

func TestResponse(t *testing.T) {
	mb, err := mailbox.Create("deployment.response")
	if err != nil {
		t.Fatal(err)
	}
	dep := &mailbox.Deployment{
		Name:        "dep",
		DeployedBy:  accessKey.Name,
		MessageBody: "testMessage",
	}
	err = dep.Create()
	if err != nil {
		t.Fatal(err)
	}
	msg, err := mb.DeployMessage(dep.Id)
	if err != nil {
		t.Fatal(err)
	}
	err = pmClient.Respond(msg.Id, "testing repsonse", false)
	if err != nil {
		t.Fatal(err)
	}

	responses, err := dep.GetResponses()
	if err != nil {
		t.Fatal(err)
	}

	if len(responses) == 0 {
		t.Fatal("Response was not added")
	}
}
开发者ID:5Sigma,项目名称:Conduit,代码行数:32,代码来源:client_test.go

示例5: generateDeployment

func generateDeployment() (*TestDeployment, error) {
	mb, err := mailbox.Create(mailbox.GenerateIdentifier())
	if err != nil {
		return nil, err
	}
	accessKey := &mailbox.AccessKey{MailboxId: mb.Id}
	err = accessKey.Create()
	if err != nil {
		return nil, err
	}
	deployment := &mailbox.Deployment{
		MessageBody: mailbox.GenerateIdentifier(),
		Name:        mailbox.GenerateIdentifier(),
		DeployedBy:  accessKey.Name,
	}
	err = deployment.Create()
	if err != nil {
		return nil, err
	}
	msg, err := deployment.Deploy(mb)
	if err != nil {
		return nil, err
	}
	return &TestDeployment{
		AccessKey:  accessKey,
		Deployment: deployment,
		Mailbox:    mb,
		Message:    msg,
	}, nil
}
开发者ID:5Sigma,项目名称:Conduit,代码行数:30,代码来源:server_test.go

示例6: TestDeploymentDetail

func TestDeploymentDetail(t *testing.T) {
	mb, err := mailbox.Create("deployment.detail")
	if err != nil {
		t.Fatal(err)
	}
	dep := mailbox.Deployment{MessageBody: "test message"}
	err = dep.Create()
	if err != nil {
		t.Fatal(err)
	}
	_, err = mb.DeployMessage(dep.Id)
	if err != nil {
		t.Fatal(err)
	}
	err = dep.AddResponse(mb.Id, "test repsonse", false)
	if err != nil {
		t.Fatal(err)
	}
	pmClient.Mailbox = mb.Id
	resp, err := pmClient.DeploymentDetail(dep.Id)
	if err != nil {
		t.Fatal(err)
	}
	if len(resp.Deployments) == 0 {
		t.Fatal("No deployments returned")
	}
	if len(resp.Deployments[0].Responses) == 0 {
		t.Fatal("No deployment responses returned")
	}
}
开发者ID:5Sigma,项目名称:Conduit,代码行数:30,代码来源:client_test.go

示例7: TestListDeploys

func TestListDeploys(t *testing.T) {
	mb, err := mailbox.Create("deployment.list")
	if err != nil {
		t.Fatal(err)
	}
	dep := &mailbox.Deployment{
		Name:        "dep",
		DeployedBy:  accessKey.Name,
		MessageBody: "test message",
	}
	err = dep.Create()
	if err != nil {
		t.Fatal(err)
	}
	_, err = mb.DeployMessage(dep.Id)
	if err != nil {
		t.Fatal(err)
	}
	pmClient.Mailbox = mb.Id
	resp, err := pmClient.ListDeploys(".*", false, 10)
	if err != nil {
		t.Fatal(err)
	}
	if len(resp.Deployments) == 0 {
		t.Fatal("No deployments returned")
	}
}
开发者ID:5Sigma,项目名称:Conduit,代码行数:27,代码来源:client_test.go

示例8: TestMain

func TestMain(m *testing.M) {
	// open database in memory for testing
	mailbox.OpenMemDB()
	err := mailbox.CreateDB()
	if err != nil {
		panic(err)
	}

	// create a default mailbox to use
	mb, err = mailbox.Create("mb")
	if err != nil {
		panic(err)
	}

	// create an access token for the default mailbox
	accessKey = &mailbox.AccessKey{FullAccess: true}
	accessKey.Create()

	// create a postmasterClient
	pmClient = client.Client{
		Host:          "localhost:4111",
		Mailbox:       mb.Id,
		AccessKeyName: accessKey.Name,
		AccessKey:     accessKey.Secret,
	}

	// Start up a test server to use
	server.EnableLongPolling = false
	go server.Start(":4111")
	retCode := m.Run()

	// cleanup
	mailbox.CloseDB()
	os.Exit(retCode)
}
开发者ID:5Sigma,项目名称:Conduit,代码行数:35,代码来源:client_test.go

示例9: TestAddResponse

func TestAddResponse(t *testing.T) {
	mb, err := mailbox.Create("tests.AddResponses")
	if err != nil {
		t.Fatal(err)
	}
	key := mailbox.AccessKey{FullAccess: true}
	key.Create()
	if err != nil {
		t.Fatal(err)
	}
	dep := mailbox.Deployment{MessageBody: "test", DeployedBy: key.Name}
	err = dep.Create()
	if err != nil {
		t.Fatal(err)
	}
	msg, err := mb.DeployMessage(dep.Id)
	if err != nil {
		t.Fatal(err)
	}
	err = dep.AddResponse(msg.Id, "response", false)
	if err != nil {
		t.Fatal(err)
	}
	responses, err := dep.GetResponses()
	if len(responses) == 0 {
		t.Fatal("Deployment has no responses")
	}
}
开发者ID:5Sigma,项目名称:Conduit,代码行数:28,代码来源:deploy_test.go

示例10: TestDelete

func TestDelete(t *testing.T) {
	mb, err := mailbox.Create("delete")
	if err != nil {
		t.Fatal(err)
	}

	msg, err := mb.PutMessage("TEST")
	if err != nil {
		t.Fatal(err)
	}

	key := mailbox.AccessKey{MailboxId: mb.Id}
	key.Create()
	req := api.DeleteMessageRequest{Message: msg.Id}
	req.Sign(key.Name, key.Secret)
	resp := api.DeleteMessageResponse{}

	statusCode := doRequest(t, req, &resp, "delete")
	if statusCode != 200 {
		t.Fatal("Server responded with", statusCode)
	}

	count, err := mb.MessageCount()
	if err != nil {
		t.Fatal(err)
	}

	if count != 0 {
		t.Fatal("Message count should be 0 but is", count)
	}
}
开发者ID:5Sigma,项目名称:Conduit,代码行数:31,代码来源:server_test.go

示例11: TestMailboxKeyName

func TestMailboxKeyName(t *testing.T) {
	mb, _ := mailbox.Create("tokentest.admin")
	key := mailbox.AccessKey{MailboxId: mb.Id}
	key.Create()
	if key.Name != mb.Id {
		t.Fatal("Key name should be set to mailbox name")
	}
}
开发者ID:5Sigma,项目名称:Conduit,代码行数:8,代码来源:access_keys_test.go

示例12: TestCreateMailboxWithKeyName

func TestCreateMailboxWithKeyName(t *testing.T) {
	key := &mailbox.AccessKey{Name: "dupmbtest", FullAccess: true}
	key.Create()
	_, err := mailbox.Create("dupmbtest")
	if err != nil {
		t.Fatal("Should not create mailbox with key name")
	}
}
开发者ID:5Sigma,项目名称:Conduit,代码行数:8,代码来源:access_keys_test.go

示例13: TestClientDelete

// TestClientDelete checks to make sure the client is capable of deleting
// messages.
func TestClientDelete(t *testing.T) {
	mb, _ := mailbox.Create("delete")
	msg, _ := mb.PutMessage("TEST DELETE")
	pmClient.Delete(msg.Id)
	count, _ := mb.MessageCount()
	if count != 0 {
		t.Fatal("Message count is", count)
	}
}
开发者ID:5Sigma,项目名称:Conduit,代码行数:11,代码来源:client_test.go

示例14: TestCreateDupKey

func TestCreateDupKey(t *testing.T) {
	mailbox.Create("dupkeytest")
	mbKey := &mailbox.AccessKey{MailboxId: "dupkeytest"}
	mbKey.Create()
	key := &mailbox.AccessKey{Name: "dupkeytest", FullAccess: true}
	err := key.Create()
	if err == nil {
		t.Fatal("Should not create key with the same name as a mailbox")
	}
}
开发者ID:5Sigma,项目名称:Conduit,代码行数:10,代码来源:access_keys_test.go

示例15: TestNoMessages

// TestNoMessage checks that a mailbox should respond with an empty response if
// there are no messages in the queue.
func TestNoMessages(t *testing.T) {
	mb, _ = mailbox.Create("empty")
	pmClient.Mailbox = mb.Id
	resp, err := pmClient.Get()
	if err != nil {
		t.Fatal(err)
	}
	if !resp.IsEmpty() {
		t.Fatal("Response body is not empty")
	}
}
开发者ID:5Sigma,项目名称:Conduit,代码行数:13,代码来源:client_test.go


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