本文整理汇总了Golang中github.com/kataras/iris.Context.Do方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.Do方法的具体用法?Golang Context.Do怎么用?Golang Context.Do使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/kataras/iris.Context
的用法示例。
在下文中一共展示了Context.Do方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestContextDoNextStop
// White-box testing *
func TestContextDoNextStop(t *testing.T) {
var context iris.Context
ok := false
afterStop := false
context.Middleware = iris.Middleware{iris.HandlerFunc(func(*iris.Context) {
ok = true
}), iris.HandlerFunc(func(*iris.Context) {
ok = true
}), iris.HandlerFunc(func(*iris.Context) {
// this will never execute
afterStop = true
})}
context.Do()
if context.Pos != 0 {
t.Fatalf("Expecting position 0 for context's middleware but we got: %d", context.Pos)
}
if !ok {
t.Fatalf("Unexpected behavior, first context's middleware didn't executed")
}
ok = false
context.Next()
if int(context.Pos) != 1 {
t.Fatalf("Expecting to have position %d but we got: %d", 1, context.Pos)
}
if !ok {
t.Fatalf("Next context's middleware didn't executed")
}
context.StopExecution()
if context.Pos != 255 {
t.Fatalf("Context's StopExecution didn't worked, we expected to have position %d but we got %d", 255, context.Pos)
}
if !context.IsStopped() {
t.Fatalf("Should be stopped")
}
context.Next()
if afterStop {
t.Fatalf("We stopped the execution but the next handler was executed")
}
}