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


Golang Message.Command方法代碼示例

本文整理匯總了Golang中github.com/eluleci/dock/messages.Message.Command方法的典型用法代碼示例。如果您正苦於以下問題:Golang Message.Command方法的具體用法?Golang Message.Command怎麽用?Golang Message.Command使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/eluleci/dock/messages.Message的用法示例。


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

示例1: TestHandleRequest

func TestHandleRequest(t *testing.T) {

	hooks.ExecuteTrigger = func(className, when, method string,
		parameters map[string][]string, body map[string]interface{}, multipart *multipart.Form,
		user interface{}) (responseBody map[string]interface{}, err *utils.Error) {
		return
	}

	isGrantedFuncThatReturnsTrue := func(collection string, requestWrapper messages.RequestWrapper, dbAdapter *adapters.MongoAdapter) (isGranted bool, user map[string]interface{}, err *utils.Error) {
		isGranted = true
		return
	}

	isGrantedFuncThatReturnsFalse := func(collection string, requestWrapper messages.RequestWrapper, dbAdapter *adapters.MongoAdapter) (isGranted bool, user map[string]interface{}, err *utils.Error) {
		isGranted = false
		return
	}

	resetFunctions()
	Convey("Should call auth.GetPermissions", t, func() {

		var called bool
		auth.IsGranted = func(collection string, requestWrapper messages.RequestWrapper, dbAdapter *adapters.MongoAdapter) (isGranted bool, user map[string]interface{}, err *utils.Error) {
			called = true
			return
		}

		actor := &Actor{}
		actor.class = "someclass"
		handleRequest(actor, messages.RequestWrapper{})
		So(called, ShouldBeTrue)
	})

	Convey("Should return permission error", t, func() {

		auth.IsGranted = func(collection string, requestWrapper messages.RequestWrapper, dbAdapter *adapters.MongoAdapter) (isGranted bool, user map[string]interface{}, err *utils.Error) {
			err = &utils.Error{http.StatusInternalServerError, ""}
			return
		}

		actor := &Actor{}
		actor.class = "someclass"
		response := handleRequest(actor, messages.RequestWrapper{})
		So(response.Status, ShouldEqual, http.StatusInternalServerError)
	})

	/////////////////////////
	// GET
	/////////////////////////
	resetFunctions()
	Convey("Should call handleGet", t, func() {

		auth.IsGranted = isGrantedFuncThatReturnsTrue

		var called bool
		handleGet = func(a *Actor, requestWrapper messages.RequestWrapper) (response messages.Message, err *utils.Error) {
			called = true
			return
		}

		var m messages.Message
		m.Command = "get"

		var rw messages.RequestWrapper
		rw.Message = m

		actor := &Actor{}
		actor.class = "someclass"
		handleRequest(actor, rw)
		So(called, ShouldBeTrue)
	})

	Convey("Should return Authorization error for GET", t, func() {

		auth.IsGranted = isGrantedFuncThatReturnsFalse

		var m messages.Message
		m.Command = "get"

		var rw messages.RequestWrapper
		rw.Message = m

		actor := &Actor{}
		actor.class = "someclass"
		response := handleRequest(actor, rw)
		So(response.Status, ShouldEqual, http.StatusUnauthorized)

	})

	/////////////////////////
	// POST
	/////////////////////////
	Convey("Should call handlePost", t, func() {

		auth.IsGranted = isGrantedFuncThatReturnsTrue

		var called bool
		handlePost = func(a *Actor, requestWrapper messages.RequestWrapper, user interface{}) (response messages.Message, hookBody map[string]interface{}, err *utils.Error) {
			called = true
			return
//.........這裏部分代碼省略.........
開發者ID:eluleci,項目名稱:dock,代碼行數:101,代碼來源:actor_test.go


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