19146: Remove unneeded special case checks, explain the needed one.
[arvados.git] / lib / controller / router / checker_test.go
1 // Copyright (C) The Arvados Authors. All rights reserved.
2 //
3 // SPDX-License-Identifier: AGPL-3.0
4
5 package router
6
7 import (
8         "reflect"
9         "runtime"
10
11         check "gopkg.in/check.v1"
12 )
13
14 // a Gocheck checker for testing the name of a function. Used with
15 // (*arvadostest.APIStub).Calls() to check that an HTTP request has
16 // been routed to the correct arvados.API method.
17 //
18 //      c.Check(bytes.NewBuffer().Read, isMethodNamed, "Read")
19 var isMethodNamed check.Checker = &chkIsMethodNamed{
20         CheckerInfo: &check.CheckerInfo{
21                 Name:   "isMethodNamed",
22                 Params: []string{"obtained", "expected"},
23         },
24 }
25
26 type chkIsMethodNamed struct{ *check.CheckerInfo }
27
28 func (*chkIsMethodNamed) Check(params []interface{}, names []string) (bool, string) {
29         methodName := runtime.FuncForPC(reflect.ValueOf(params[0]).Pointer()).Name()
30         regex := `.*\)\.` + params[1].(string) + `(-.*)?`
31         return check.Matches.Check([]interface{}{methodName, regex}, names)
32 }