File: before_after_filter_test.go

package info (click to toggle)
golang-github-revel-revel 1.0.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,240 kB
  • sloc: xml: 7; makefile: 7; javascript: 1
file content (51 lines) | stat: -rw-r--r-- 1,141 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright (c) 2019 The Revel Framework Authors, All rights reserved.
// Revel Framework source code and usage is governed by a MIT style
// license that can be found in the LICENSE file.

package revel

import (
	"testing"
)

type bafTestController struct {
	*Controller
}

func (c bafTestController) Before() (Result, bafTestController) {
	return c.Redirect("http://www.example.com"), c
}

func (c bafTestController) Index() Result {
	// We shouldn't get here
	panic("Should not be called")
}

type failingFilter struct {
	t *testing.T
}

func (f failingFilter) FailIfCalled(c *Controller, filterChain []Filter) {
	f.t.Error("Filter should not have been called")
}

func TestInterceptorsNotCalledIfBeforeReturns(t *testing.T) {
	Init("prod", "github.com/revel/revel/testdata", "")
	controllers = make(map[string]*ControllerType)
	RegisterController((*bafTestController)(nil), []*MethodType{
		{
			Name: "Before",
		},
		{
			Name: "Index",
		},
	})

	c := NewControllerEmpty()
	err := c.SetAction("bafTestController", "Index")
	if err != nil {
		t.Error(err.Error())
	}

	BeforeAfterFilter(c, []Filter{failingFilter{t}.FailIfCalled})
}