當前位置: 首頁>>代碼示例>>Golang>>正文


Golang mbus.NewRequest函數代碼示例

本文整理匯總了Golang中bosh/mbus.NewRequest函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewRequest函數的具體用法?Golang NewRequest怎麽用?Golang NewRequest使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewRequest函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: TestRunHandlesAPingMessage

func TestRunHandlesAPingMessage(t *testing.T) {
	taskService := &testtask.FakeService{}
	req := boshmbus.NewRequest("reply to me!", "ping", []byte("some payload"))
	expectedResp := boshmbus.Response{Value: "pong"}

	assertResponseForRequest(t, taskService, req, expectedResp)
}
開發者ID:sbb,項目名稱:bosh,代碼行數:7,代碼來源:agent_test.go

示例2: TestRunHandlesGetTaskMessageWhenPayloadDoesNotHaveTaskId

func TestRunHandlesGetTaskMessageWhenPayloadDoesNotHaveTaskId(t *testing.T) {
	taskService := &testtask.FakeService{
		Tasks: map[string]boshtask.Task{},
	}

	req := boshmbus.NewRequest("reply to me!", "get_task", []byte(`{"arguments":[]}`))
	expectedResp := boshmbus.Response{Exception: "Error finding task, not enough arguments"}

	assertResponseForRequest(t, taskService, req, expectedResp)
}
開發者ID:sbb,項目名稱:bosh,代碼行數:10,代碼來源:agent_test.go

示例3: TestRunHandlesGetTaskMessageWhenTaskIsNotFound

func TestRunHandlesGetTaskMessageWhenTaskIsNotFound(t *testing.T) {
	taskService := &testtask.FakeService{
		Tasks: map[string]boshtask.Task{},
	}

	req := boshmbus.NewRequest("reply to me!", "get_task", []byte(`{"arguments":["57"]}`))
	expectedResp := boshmbus.Response{Exception: "Task with id 57 could not be found"}

	assertResponseForRequest(t, taskService, req, expectedResp)
}
開發者ID:sbb,項目名稱:bosh,代碼行數:10,代碼來源:agent_test.go

示例4: TestRunHandlesGetTaskMessage

func TestRunHandlesGetTaskMessage(t *testing.T) {
	taskService := &testtask.FakeService{
		Tasks: map[string]boshtask.Task{
			"57": boshtask.Task{Id: "found-57-task-id", State: boshtask.TaskStateFailed},
		},
	}

	req := boshmbus.NewRequest("reply to me!", "get_task", []byte(`{"arguments":["57"]}`))
	expectedResp := boshmbus.Response{State: boshtask.TaskStateFailed, AgentTaskId: "found-57-task-id"}

	assertResponseForRequest(t, taskService, req, expectedResp)
}
開發者ID:sbb,項目名稱:bosh,代碼行數:12,代碼來源:agent_test.go

示例5: TestRunHandlesAnApplyMessage

func TestRunHandlesAnApplyMessage(t *testing.T) {
	taskService := &testtask.FakeService{
		StartTaskStartedTask: boshtask.Task{
			Id:    "some-task-id",
			State: "running",
		},
	}

	req := boshmbus.NewRequest("reply to me!", "apply", []byte("some payload"))
	expectedResp := boshmbus.Response{State: "running", AgentTaskId: "some-task-id"}

	assertResponseForRequestWithTask(t, taskService, req, expectedResp)
}
開發者ID:sbb,項目名稱:bosh,代碼行數:13,代碼來源:agent_test.go

示例6: TestRunRespondsWithExceptionWhenTheMethodIsUnknown

func TestRunRespondsWithExceptionWhenTheMethodIsUnknown(t *testing.T) {
	req := boshmbus.NewRequest("reply to me", "gibberish", []byte{})

	settings, handler, platform, taskService, actionFactory := getAgentDependencies()
	agent := New(settings, handler, platform, taskService, actionFactory)

	err := agent.Run()
	assert.NoError(t, err)
	assert.True(t, handler.ReceivedRun)

	resp := handler.Func(req)

	boshassert.MatchesJsonString(t, resp, `{"exception":{"message":"unknown message gibberish"}}`)
}
開發者ID:joanesespanol,項目名稱:bosh,代碼行數:14,代碼來源:agent_test.go

示例7: TestDispatchRespondsWithExceptionWhenTheMethodIsUnknown

func TestDispatchRespondsWithExceptionWhenTheMethodIsUnknown(t *testing.T) {
	logger, taskService, actionFactory, actionRunner := getActionDispatcherDependencies()

	req := boshmbus.NewRequest("reply to me", "gibberish", []byte{})

	actionFactory.CreateErr = true

	dispatcher := NewActionDispatcher(logger, taskService, actionFactory, actionRunner)

	resp := dispatcher.Dispatch(req)

	boshassert.MatchesJsonString(t, resp, `{"exception":{"message":"unknown message gibberish"}}`)
	assert.Equal(t, actionFactory.CreateMethod, "gibberish")
}
開發者ID:kangaroo,項目名稱:bosh,代碼行數:14,代碼來源:action_dispatcher_test.go

示例8: TestRunSetsTheDispatcherAsMessageHandler

func TestRunSetsTheDispatcherAsMessageHandler(t *testing.T) {
	deps, agent := buildAgent()
	deps.actionDispatcher.DispatchResp = boshmbus.NewValueResponse("pong")

	err := agent.Run()

	assert.NoError(t, err)
	assert.True(t, deps.handler.ReceivedRun)

	req := boshmbus.NewRequest("reply to me!", "some action", []byte("some payload"))
	resp := deps.handler.Func(req)

	assert.Equal(t, deps.actionDispatcher.DispatchReq, req)
	assert.Equal(t, resp, deps.actionDispatcher.DispatchResp)
}
開發者ID:kangaroo,項目名稱:bosh,代碼行數:15,代碼來源:agent_test.go

示例9: TestDispatchHandlesSynchronousActionWhenErr

func TestDispatchHandlesSynchronousActionWhenErr(t *testing.T) {
	logger, taskService, actionFactory, actionRunner := getActionDispatcherDependencies()

	// when action returns an error
	actionFactory.CreateAction = &fakeaction.TestAction{}
	actionRunner.RunErr = errors.New("some error")

	dispatcher := NewActionDispatcher(logger, taskService, actionFactory, actionRunner)

	req := boshmbus.NewRequest("reply to me!", "some action", []byte("some payload"))
	resp := dispatcher.Dispatch(req)
	expectedJson := fmt.Sprintf("{\"exception\":{\"message\":\"Action Failed %s: some error\"}}", req.Method)
	boshassert.MatchesJsonString(t, resp, expectedJson)
	assert.Equal(t, actionFactory.CreateMethod, "some action")
}
開發者ID:kangaroo,項目名稱:bosh,代碼行數:15,代碼來源:action_dispatcher_test.go

示例10: TestRunSetsTheDispatcherAsMessageHandler

func TestRunSetsTheDispatcherAsMessageHandler(t *testing.T) {
	settings, logger, handler, platform, actionDispatcher := getAgentDependencies()
	actionDispatcher.DispatchResp = boshmbus.NewValueResponse("pong")

	agent := New(settings, logger, handler, platform, actionDispatcher)
	err := agent.Run()

	assert.NoError(t, err)
	assert.True(t, handler.ReceivedRun)

	req := boshmbus.NewRequest("reply to me!", "some action", []byte("some payload"))
	resp := handler.Func(req)

	assert.Equal(t, actionDispatcher.DispatchReq, req)
	assert.Equal(t, resp, actionDispatcher.DispatchResp)
}
開發者ID:viglesiasce,項目名稱:bosh,代碼行數:16,代碼來源:agent_test.go

示例11: TestDispatchHandlesSynchronousAction

func TestDispatchHandlesSynchronousAction(t *testing.T) {
	logger, taskService, actionFactory, actionRunner := getActionDispatcherDependencies()

	// when action is successful
	actionFactory.CreateAction = &fakeaction.TestAction{
		Asynchronous: false,
	}
	actionRunner.RunValue = "some value"

	dispatcher := NewActionDispatcher(logger, taskService, actionFactory, actionRunner)

	req := boshmbus.NewRequest("reply to me!", "some action", []byte("some payload"))
	resp := dispatcher.Dispatch(req)
	assert.Equal(t, req.Method, actionFactory.CreateMethod)
	assert.Equal(t, req.GetPayload(), actionRunner.RunPayload)
	assert.Equal(t, boshmbus.NewValueResponse("some value"), resp)
}
開發者ID:kangaroo,項目名稱:bosh,代碼行數:17,代碼來源:action_dispatcher_test.go

示例12: TestDispatchHandlesAsynchronousAction

func TestDispatchHandlesAsynchronousAction(t *testing.T) {
	logger, taskService, actionFactory, actionRunner := getActionDispatcherDependencies()

	taskService.StartTaskStartedTask = boshtask.Task{Id: "found-57-id", State: boshtask.TaskStateDone}
	actionFactory.CreateAction = &fakeaction.TestAction{
		Asynchronous: true,
	}
	actionRunner.RunValue = "some-task-result-value"

	dispatcher := NewActionDispatcher(logger, taskService, actionFactory, actionRunner)
	req := boshmbus.NewRequest("reply to me!", "some async action", []byte("some payload"))
	resp := dispatcher.Dispatch(req)

	boshassert.MatchesJsonString(t, resp, `{"value":{"agent_task_id":"found-57-id","state":"done"}}`)

	value, err := taskService.StartTaskFunc()
	assert.NoError(t, err)
	assert.Equal(t, "some-task-result-value", value)

	assert.Equal(t, req.Method, actionFactory.CreateMethod)
	assert.Equal(t, req.GetPayload(), actionRunner.RunPayload)
	assert.Equal(t, actionFactory.CreateMethod, "some async action")
}
開發者ID:kangaroo,項目名稱:bosh,代碼行數:23,代碼來源:action_dispatcher_test.go

示例13: TestRunHandlesGetStateMessage

func TestRunHandlesGetStateMessage(t *testing.T) {
	req := boshmbus.NewRequest("reply to me!", "get_state", []byte(`{}`))
	assertRequestIsProcessedSynchronously(t, req)
}
開發者ID:joanesespanol,項目名稱:bosh,代碼行數:4,代碼來源:agent_test.go

示例14: TestRunHandlesGetTaskMessage

func TestRunHandlesGetTaskMessage(t *testing.T) {
	req := boshmbus.NewRequest("reply to me!", "get_task", []byte(`{"arguments":["57"]}`))
	assertRequestIsProcessedSynchronously(t, req)
}
開發者ID:joanesespanol,項目名稱:bosh,代碼行數:4,代碼來源:agent_test.go

示例15: TestRunHandlesPingMessage

func TestRunHandlesPingMessage(t *testing.T) {
	req := boshmbus.NewRequest("reply to me!", "ping", []byte("some payload"))
	assertRequestIsProcessedSynchronously(t, req)
}
開發者ID:joanesespanol,項目名稱:bosh,代碼行數:4,代碼來源:agent_test.go


注:本文中的bosh/mbus.NewRequest函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。