// 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") } }