本文整理汇总了Golang中testing.T.Name方法的典型用法代码示例。如果您正苦于以下问题:Golang T.Name方法的具体用法?Golang T.Name怎么用?Golang T.Name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testing.T
的用法示例。
在下文中一共展示了T.Name方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestPrefixedSchemaName
func TestPrefixedSchemaName(t *testing.T) {
const prefix = "SomePrefix"
origSchemaNameForType := SchemaNameForType
defer func() { SchemaNameForType = origSchemaNameForType }()
SchemaNameForType = func(t reflect.Type) string {
return prefix + t.Name()
}
d := createDescriptor(t)
for name := range d.Descriptor.Schemas {
if !strings.HasPrefix(name, prefix) {
t.Errorf("HasPrefix(%q, %q) = false", name, prefix)
}
}
for mname, meth := range d.Descriptor.Methods {
if meth.Request != nil {
if !strings.HasPrefix(meth.Request.Ref, prefix) {
t.Errorf("HasPrefix(%q, %q) = false; request of %q",
meth.Request.Ref, prefix, mname)
}
}
if meth.Response != nil {
if !strings.HasPrefix(meth.Response.Ref, prefix) {
t.Errorf("HasPrefix(%q, %q) = false; response of %q",
meth.Response.Ref, prefix, mname)
}
}
}
}
示例2: TestGrammar
func TestGrammar(t *testing.T) {
bnf0 := GenerateBnf0Grammar()
g := GetIndexedGrammar(bnf0)
idxIf, err := g.GetIndex(GrammarIndexTypeTerm)
if err != nil {
t.Error(err)
return
}
termIndex := idxIf.(TermGrammarIndex)
for _, ntn := range termIndex.GetNonterminalNames() {
nt, _ := termIndex.GetNonterminal(ntn)
fmt.Printf("%d: <%s>\n", nt.Id(), nt.Name())
}
for _, tn := range termIndex.GetTerminalNames() {
t, _ := termIndex.GetTerminal(tn)
fmt.Printf("%d: %s\n", t.Id(), t.Name())
}
}
示例3: TestTaskQueue
func TestTaskQueue(t *testing.T) {
t.Parallel()
Convey("TaskQueue", t, func() {
now := time.Date(2000, time.January, 1, 1, 1, 1, 1, time.UTC)
c, tc := testclock.UseTime(context.Background(), now)
c = mathrand.Set(c, rand.New(rand.NewSource(clock.Now(c).UnixNano())))
c = Use(c)
tq := tqS.Get(c)
tqt := tq.Testable()
So(tqt, ShouldNotBeNil)
So(tq, ShouldNotBeNil)
Convey("implements TQMultiReadWriter", func() {
Convey("Add", func() {
t := tq.NewTask("/hello/world")
Convey("works", func() {
t.Delay = 4 * time.Second
t.Header = http.Header{}
t.Header.Add("Cat", "tabby")
t.Payload = []byte("watwatwat")
t.RetryOptions = &tqS.RetryOptions{AgeLimit: 7 * time.Second}
So(tq.Add(t, ""), ShouldBeNil)
name := "Z_UjshxM9ecyMQfGbZmUGOEcgxWU0_5CGLl_-RntudwAw2DqQ5-58bzJiWQN4OKzeuUb9O4JrPkUw2rOvk2Ax46THojnQ6avBQgZdrKcJmrwQ6o4qKfJdiyUbGXvy691yRfzLeQhs6cBhWrgf3wH-VPMcA4SC-zlbJ2U8An7I0zJQA5nBFnMNoMgT-2peGoay3rCSbj4z9VFFm9kS_i6JCaQH518ujLDSNCYdjTq6B6lcWrZAh0U_q3a1S2nXEwrKiw_t9MTNQFgAQZWyGBbvZQPmeRYtu8SPaWzTfd25v_YWgBuVL2rRSPSMvlDwE04nNdtvVzE8vNNiA1zRimmdzKeqATQF9_ReUvj4D7U8dcS703DZWfKMBLgBffY9jqCassOOOw77V72Oq5EVauUw3Qw0L6bBsfM9FtahTKUdabzRZjXUoze3EK4KXPt3-wdidau-8JrVf2XFocjjZbwHoxcGvbtT3b4nGLDlgwdC00bwaFBZWff"
So(tqt.GetScheduledTasks()["default"][name], ShouldResemble, &tqS.Task{
ETA: now.Add(4 * time.Second),
Header: http.Header{"Cat": []string{"tabby"}},
Method: "POST",
Name: name,
Path: "/hello/world",
Payload: []byte("watwatwat"),
RetryOptions: &tqS.RetryOptions{AgeLimit: 7 * time.Second},
})
})
Convey("picks up namespace", func() {
c, err := info.Get(c).Namespace("coolNamespace")
So(err, ShouldBeNil)
tq = tqS.Get(c)
t := tq.NewTask("")
So(tq.Add(t, ""), ShouldBeNil)
So(t.Header, ShouldResemble, http.Header{
"X-Appengine-Current-Namespace": {"coolNamespace"},
})
})
Convey("cannot add to bad queues", func() {
So(tq.Add(nil, "waaat").Error(), ShouldContainSubstring, "UNKNOWN_QUEUE")
Convey("but you can add Queues when testing", func() {
tqt.CreateQueue("waaat")
So(tq.Add(t, "waaat"), ShouldBeNil)
Convey("you just can't add them twice", func() {
So(func() { tqt.CreateQueue("waaat") }, ShouldPanic)
})
})
})
Convey("supplies a URL if it's missing", func() {
t.Path = ""
So(tq.Add(t, ""), ShouldBeNil)
So(t.Path, ShouldEqual, "/_ah/queue/default")
})
Convey("cannot add twice", func() {
t.Name = "bob"
So(tq.Add(t, ""), ShouldBeNil)
// can't add the same one twice!
So(tq.Add(t, ""), ShouldEqual, tqS.ErrTaskAlreadyAdded)
})
Convey("cannot add deleted task", func() {
t.Name = "bob"
So(tq.Add(t, ""), ShouldBeNil)
So(tq.Delete(t, ""), ShouldBeNil)
// can't add a deleted task!
So(tq.Add(t, ""), ShouldEqual, tqS.ErrTaskAlreadyAdded)
})
Convey("cannot set ETA+Delay", func() {
t.ETA = clock.Now(c).Add(time.Hour)
tc.Add(time.Second)
t.Delay = time.Hour
So(func() {
So(tq.Add(t, ""), ShouldBeNil)
}, ShouldPanic)
})
Convey("must use a reasonable method", func() {
t.Method = "Crystal"
//.........这里部分代码省略.........
示例4: TestFindTypeCycles
func TestFindTypeCycles(t *testing.T) {
tests := []struct {
desc string
typ TypeSpec
msgs []string
}{
{
desc: "self-referential typedef",
typ: withTypedef(func(t *TypedefSpec) {
t.Name = "foo"
t.Target = t
}),
msgs: []string{
"found a type reference cycle",
" foo",
"-> foo",
},
},
{
desc: "mutually recursive references",
typ: withTypedef(func(x *TypedefSpec) {
x.Name = "foo"
x.Target = &TypedefSpec{
Name: "bar",
File: "test.thrift",
Target: x,
}
}),
msgs: []string{
"found a type reference cycle",
" foo",
"-> bar",
"-> foo",
},
},
{
desc: "recurse from map",
typ: withTypedef(func(t *TypedefSpec) {
t.Name = "foo"
t.Target = &MapSpec{
KeySpec: &StringSpec{},
ValueSpec: t,
}
}),
msgs: []string{
"found a type reference cycle",
" foo",
"-> map<string, foo>",
"-> foo",
},
},
{
desc: "recurse from list",
typ: withTypedef(func(t *TypedefSpec) {
t.Name = "foo"
t.Target = &ListSpec{ValueSpec: t}
}),
msgs: []string{
"found a type reference cycle",
" foo",
"-> list<foo>",
"-> foo",
},
},
{
desc: "recurse from set",
typ: withTypedef(func(t *TypedefSpec) {
t.Name = "foo"
t.Target = &SetSpec{ValueSpec: t}
}),
msgs: []string{
"found a type reference cycle",
" foo",
"-> set<foo>",
"-> foo",
},
},
{
desc: "recurse from struct",
typ: withTypedef(func(t *TypedefSpec) {
t.Name = "foo"
t.Target = &StructSpec{
Name: "bar",
File: "test.thrift",
Type: ast.StructType,
Fields: FieldGroup{
{
ID: 1,
Name: "foo",
Type: t,
Required: true,
},
},
}
}),
},
}
for _, tt := range tests {
typ := mustLink(t, tt.typ, defaultScope)
//.........这里部分代码省略.........
示例5: TestApiClient
func TestApiClient(t *testing.T) {
done := make(chan struct{})
defer func() {
close(done)
time.Sleep(time.Second)
}()
url := startApi(done)
agentCount := 1
metricsCount := 2
taskCount := 0
Convey("Client should exist", t, func() {
c, cerr := New(url, adminKey, false)
So(cerr, ShouldBeNil)
Convey("When calling the api heartbeat method", func() {
ok, hErr := c.Heartbeat()
So(hErr, ShouldBeNil)
So(ok, ShouldBeTrue)
})
Convey("when adding a new Agent", func() {
agentCount++
pre := time.Now()
a := model.AgentDTO{
Name: fmt.Sprintf("demo%d", agentCount),
Enabled: true,
Public: false,
Tags: []string{"demo", "private"},
}
aErr := c.AddAgent(&a)
So(aErr, ShouldBeNil)
So(a.Id, ShouldNotBeEmpty)
So(a.Name, ShouldEqual, fmt.Sprintf("demo%d", agentCount))
So(a.Enabled, ShouldEqual, true)
So(a.Public, ShouldEqual, false)
So(a.Created, ShouldHappenBefore, time.Now())
So(a.Created, ShouldHappenAfter, pre)
So(a.Created.Unix(), ShouldEqual, a.Updated.Unix())
Convey("when getting an agent by id", func() {
agent, err := c.GetAgentById(a.Id)
So(err, ShouldBeNil)
So(agent, ShouldNotBeNil)
So(agent, ShouldHaveSameTypeAs, &model.AgentDTO{})
So(agent.Id, ShouldEqual, a.Id)
So(agent.Created.Unix(), ShouldEqual, a.Created.Unix())
Convey("when updating an Agent", func() {
a := new(model.AgentDTO)
*a = *agent
a.Name = "test1"
pre := time.Now()
err := c.UpdateAgent(a)
So(err, ShouldBeNil)
So(a.Id, ShouldNotBeEmpty)
So(a.Name, ShouldEqual, "test1")
So(a.Enabled, ShouldEqual, true)
So(a.Public, ShouldEqual, false)
So(a.Created, ShouldHappenBefore, pre)
So(a.Updated, ShouldHappenAfter, pre)
})
Convey("When deleting an agent", func() {
err := c.DeleteAgent(&a)
So(err, ShouldBeNil)
agentCount--
Convey("When searching for agent by name", func() {
query := model.GetAgentsQuery{Name: a.Name}
agents, err := c.GetAgents(&query)
So(err, ShouldBeNil)
So(len(agents), ShouldEqual, 0)
})
})
})
Convey("When getting the list of Agents", func() {
query := model.GetAgentsQuery{}
agents, err := c.GetAgents(&query)
So(err, ShouldBeNil)
So(len(agents), ShouldEqual, agentCount)
})
})
Convey("When getting list of public agenst", func() {
query := model.GetAgentsQuery{Public: "true"}
agents, err := c.GetAgents(&query)
So(err, ShouldBeNil)
So(len(agents), ShouldEqual, 1)
So(agents[0].Id, ShouldEqual, 1)
Convey("When updating tags of public agent", func() {
a := new(model.AgentDTO)
*a = *agents[0]
a.Tags = []string{"foo", "demo"}
err := c.UpdateAgent(a)
So(err, ShouldBeNil)
So(a.Id, ShouldNotBeEmpty)
So(a.Name, ShouldEqual, "publicTest")
//.........这里部分代码省略.........