本文整理汇总了Golang中postmaster/mailbox.AccessKey类的典型用法代码示例。如果您正苦于以下问题:Golang AccessKey类的具体用法?Golang AccessKey怎么用?Golang AccessKey使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AccessKey类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestDeployListByName
func TestDeployListByName(t *testing.T) {
deployment1, err := generateDeployment()
if err != nil {
t.Fatal(err)
}
deployment1.Deployment.Name = "test"
deployment1.Deployment.Save()
generateDeployment()
if err != nil {
t.Fatal(err)
}
key := mailbox.AccessKey{FullAccess: true}
key.Create()
req := api.DeploymentStatsRequest{
Count: 10,
NamePattern: "t*t",
}
req.Sign(key.Name, key.Secret)
var resp api.DeploymentStatsResponse
code := doRequest(t, req, &resp, "deploy/list")
if code != 200 {
t.Fatalf("Server repsponded with %d", code)
}
if len(resp.Deployments) != 1 {
t.Fatalf("Deployment length %d != 1", len(resp.Deployments))
}
}
示例2: 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")
}
}
示例3: TestDeployInfoListByToken
func TestDeployInfoListByToken(t *testing.T) {
_, err := generateDeployment()
key := mailbox.AccessKey{FullAccess: true}
key.Create()
if err != nil {
t.Fatal(err)
}
dep2, err := generateDeployment()
if err != nil {
t.Fatal(err)
}
req := api.DeploymentStatsRequest{
Count: 2,
TokenPattern: dep2.AccessKey.Name,
}
req.Sign(key.Name, key.Secret)
var resp api.DeploymentStatsResponse
code := doRequest(t, req, &resp, "deploy/list")
if code != 200 {
t.Fatalf("Server repsponded with %d", code)
}
if len(resp.Deployments) != 1 {
t.Fatalf("Deployment count %d!=1", len(resp.Deployments))
}
}
示例4: 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")
}
}
示例5: 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)
}
}
示例6: 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")
}
}
示例7: 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)
}
}
示例8: TestBadMailbox
func TestBadMailbox(t *testing.T) {
key := mailbox.AccessKey{FullAccess: true}
key.Create()
req := api.GetMessageRequest{Mailbox: "111"}
req.Sign(key.Name, key.Secret)
var resp api.GetMessageResponse
code := doRequest(t, req, &resp, "get")
if code != 400 {
t.Fatal("Should of responded with 400 but it responded with", code)
}
}
示例9: TestCreateAPIToken
func TestCreateAPIToken(t *testing.T) {
mb, _ := mailbox.Create("tokentest.admin")
key := mailbox.AccessKey{FullAccess: true}
err := key.Create()
if err != nil {
t.Fatal(err)
}
if !key.CanPut(mb) {
t.Fatal("Admin token not able to put messages.")
}
}
示例10: TestSystemStats
func TestSystemStats(t *testing.T) {
mailbox.Create("stats.systemtest")
req := api.SimpleRequest{}
accessKey := mailbox.AccessKey{FullAccess: true}
accessKey.Create()
req.Sign(accessKey.Name, accessKey.Secret)
var resp api.SystemStatsResponse
code := doRequest(t, req, &resp, "stats")
if code != 200 {
t.Fatal("Server responded with", code)
}
}
示例11: TestPutBadToken
func TestPutBadToken(t *testing.T) {
mb, _ := mailbox.Create("puttest.badtoken")
accessKey := mailbox.AccessKey{MailboxId: mb.Id}
accessKey.Create()
req := api.PutMessageRequest{
Mailboxes: []string{mb.Id},
Body: "TEST MESSAGE",
}
req.Sign(accessKey.Name, accessKey.Secret)
var resp api.PutMessageResponse
code := doRequest(t, req, &resp, "put")
if code == 200 {
t.Fatal("Bad token should return error")
}
}
示例12: TestAgentCommand
func TestAgentCommand(t *testing.T) {
mailbox.OpenMemDB()
key := mailbox.AccessKey{FullAccess: true}
key.Create()
agent.Address = ":6112"
agent.AccessKey = key.Secret
go agent.Start()
engine.Agents["test"] = ":6112"
engine.AgentAccessKey = key.Secret
eng := engine.New()
err := eng.Execute(`$agent("test", function() { console.log("test"); });`)
if err != nil {
t.Fatal(err)
}
}
示例13: TestDeployInfoList
func TestDeployInfoList(t *testing.T) {
mb, _ := mailbox.Create("stats.deployinfo")
mb.PutMessage("test")
mb.PutMessage("test2")
key := mailbox.AccessKey{FullAccess: true}
key.Create()
req := api.DeploymentStatsRequest{Count: 2}
req.Sign(key.Name, key.Secret)
var resp api.DeploymentStatsResponse
code := doRequest(t, req, &resp, "deploy/list")
if code != 200 {
t.Fatalf("Server repsponded with %d", code)
}
if len(resp.Deployments) != 2 {
t.Fatalf("Deployment count %d!=2", len(resp.Deployments))
}
}
示例14: TestPutByPattern
func TestPutByPattern(t *testing.T) {
mb, _ := mailbox.Create("PATTERN")
accessKey := mailbox.AccessKey{FullAccess: true}
accessKey.Create()
req := api.PutMessageRequest{Pattern: "P*"}
req.Sign(accessKey.Name, accessKey.Secret)
var resp api.PutMessageResponse
code := doRequest(t, req, &resp, "put")
count, err := mb.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)
}
}
示例15: TestDeploy
func TestDeploy(t *testing.T) {
mailbox.OpenMemDB()
mailbox.CreateDB()
os.Create("test.js")
file, err := os.OpenFile("test.js", os.O_APPEND|os.O_WRONLY, 0644)
file.WriteString("console.log('test');")
file.Close()
mb, err := mailbox.Create("test.test")
if err != nil {
t.Fatal(err)
}
if err != nil {
t.Fatal(err)
}
key := mailbox.AccessKey{FullAccess: true}
err = key.Create()
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{})
deployCmd.ParseFlags([]string{"-x"})
deployCmd.Run(deployCmd, []string{"test.js", "test.test"})
os.Remove("test.js")
msg, err := mb.GetMessage()
if err != nil {
t.Fatal(err)
}
if msg == nil {
t.Fatal("No message waiting")
}
}