fleet/server/test/functions.go
Zachary Wasserman 7f757d3144 Extract functionName into helper
Cleans up some repetition in tests.
2020-07-21 14:05:46 -07:00

16 lines
376 B
Go

package test
import (
"reflect"
"runtime"
"strings"
)
// FunctionName returns the name of the function provided as the argument.
// Behavior is undefined if a non-function is passed.
func FunctionName(f interface{}) string {
fullName := runtime.FuncForPC(reflect.ValueOf(f).Pointer()).Name()
elements := strings.Split(fullName, ".")
return elements[len(elements)-1]
}