39 Star 144 Fork 3

Gitee 极速下载/grafana

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/grafana/grafana
克隆/下载
discovery.go 2.39 KB
一键复制 编辑 原始数据 按行查看 历史
Torkel Ödegaard 提交于 2015-01-16 15:48 . Godep is acting strangly
package convey
type actionSpecifier uint8
const (
noSpecifier actionSpecifier = iota
skipConvey
focusConvey
)
type suite struct {
Situation string
Test t
Focus bool
Func func(C) // nil means skipped
FailMode FailureMode
}
func newSuite(situation string, failureMode FailureMode, f func(C), test t, specifier actionSpecifier) *suite {
ret := &suite{
Situation: situation,
Test: test,
Func: f,
FailMode: failureMode,
}
switch specifier {
case skipConvey:
ret.Func = nil
case focusConvey:
ret.Focus = true
}
return ret
}
func discover(items []interface{}) *suite {
name, items := parseName(items)
test, items := parseGoTest(items)
failure, items := parseFailureMode(items)
action, items := parseAction(items)
specifier, items := parseSpecifier(items)
if len(items) != 0 {
conveyPanic(parseError)
}
return newSuite(name, failure, action, test, specifier)
}
func item(items []interface{}) interface{} {
if len(items) == 0 {
conveyPanic(parseError)
}
return items[0]
}
func parseName(items []interface{}) (string, []interface{}) {
if name, parsed := item(items).(string); parsed {
return name, items[1:]
}
conveyPanic(parseError)
panic("never get here")
}
func parseGoTest(items []interface{}) (t, []interface{}) {
if test, parsed := item(items).(t); parsed {
return test, items[1:]
}
return nil, items
}
func parseFailureMode(items []interface{}) (FailureMode, []interface{}) {
if mode, parsed := item(items).(FailureMode); parsed {
return mode, items[1:]
}
return FailureInherits, items
}
func parseAction(items []interface{}) (func(C), []interface{}) {
switch x := item(items).(type) {
case nil:
return nil, items[1:]
case func(C):
return x, items[1:]
case func():
return func(C) { x() }, items[1:]
}
conveyPanic(parseError)
panic("never get here")
}
func parseSpecifier(items []interface{}) (actionSpecifier, []interface{}) {
if len(items) == 0 {
return noSpecifier, items
}
if spec, ok := items[0].(actionSpecifier); ok {
return spec, items[1:]
}
conveyPanic(parseError)
panic("never get here")
}
// This interface allows us to pass the *testing.T struct
// throughout the internals of this package without ever
// having to import the "testing" package.
type t interface {
Fail()
}
const parseError = "You must provide a name (string), then a *testing.T (if in outermost scope), an optional FailureMode, and then an action (func())."
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
JavaScript
1
https://gitee.com/mirrors/grafana.git
git@gitee.com:mirrors/grafana.git
mirrors
grafana
grafana
v3.1.1

搜索帮助

344bd9b3 5694891 D2dac590 5694891