本文整理汇总了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)
}
}
示例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)
}
}
示例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")
}
}
示例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")
}
}
示例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
}
示例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")
}
}
示例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")
}
}
示例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)
}
示例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")
}
}
示例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)
}
}
示例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")
}
}
示例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")
}
}
示例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)
}
}
示例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")
}
}
示例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")
}
}