本文整理汇总了Golang中testing.T.Get方法的典型用法代码示例。如果您正苦于以下问题:Golang T.Get方法的具体用法?Golang T.Get怎么用?Golang T.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testing.T
的用法示例。
在下文中一共展示了T.Get方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Test_PostgresCacher
func Test_PostgresCacher(t *testing.T) {
Convey("Test postgres cache adapter", t, func() {
Convey("Basic operations", func() {
t := tango.New()
t.Use(cache.New(opt))
t.Get("/", new(CacheAction))
resp := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)
t.ServeHTTP(resp, req)
})
Convey("Increase and decrease operations", func() {
t := tango.New()
t.Use(cache.New(opt))
t.Get("/", new(Cache2Action))
resp := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)
t.ServeHTTP(resp, req)
})
})
}
示例2: Test_LedisCacher
func Test_LedisCacher(t *testing.T) {
Convey("Test ledis cache adapter", t, func() {
opt := cache.Options{
Adapter: "ledis",
AdapterConfig: "data_dir=./tmp.db",
Interval: 1,
}
Convey("Basic operations", func() {
t := tango.New()
t.Use(cache.New(opt))
t.Get("/", new(CacheAction))
resp := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)
t.ServeHTTP(resp, req)
t.Get("/id", new(Cache2Action))
resp = httptest.NewRecorder()
req, err = http.NewRequest("GET", "/id", nil)
So(err, ShouldBeNil)
t.ServeHTTP(resp, req)
})
})
}
示例3: Test_MemcacheCacher
func Test_MemcacheCacher(t *testing.T) {
Convey("Test memcache cache adapter", t, func() {
opt := cache.Options{
Adapter: "memcache",
AdapterConfig: "127.0.0.1:9090",
}
Convey("Basic operations", func() {
t := tango.New()
t.Use(cache.New(opt))
t.Get("/", new(CacheAction))
resp := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)
t.ServeHTTP(resp, req)
})
Convey("Increase and decrease operations", func() {
t := tango.New()
t.Use(cache.New(opt))
t.Get("/", new(Cache2Action))
resp := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)
t.ServeHTTP(resp, req)
})
})
}
示例4: Test_RedisCacher
func Test_RedisCacher(t *testing.T) {
Convey("Test redis cache adapter", t, func() {
opt := cache.Options{
Adapter: "redis",
AdapterConfig: "addr=:6379,prefix=cache:",
}
Convey("Basic operations", func() {
t := tango.New()
t.Use(cache.New(opt))
t.Get("/", new(CacheAction))
resp := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)
t.ServeHTTP(resp, req)
})
Convey("Increase and decrease operations", func() {
t := tango.New()
t.Use(cache.New(opt))
t.Get("/", new(Cache2Action))
resp := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)
t.ServeHTTP(resp, req)
})
})
}
示例5: TestTagErrors
func TestTagErrors(t *testing.T) {
called := false
c := NewCache(func(t reflect.StructTag) (string, bool, interface{}, error) {
called = true
s := t.Get("f")
if s == "bad" {
return "", false, nil, errors.New("error")
}
return s, true, nil, nil
}, nil)
type T struct {
X int `f:"ok"`
Y int `f:"bad"`
}
_, err := c.Fields(reflect.TypeOf(T{}))
if !called {
t.Fatal("tag parser not called")
}
if err == nil {
t.Error("want error, got nil")
}
// Second time, we should cache the error.
called = false
_, err = c.Fields(reflect.TypeOf(T{}))
if called {
t.Fatal("tag parser called on second time")
}
if err == nil {
t.Error("want error, got nil")
}
}
示例6: Test_Cacher
func Test_Cacher(t *testing.T) {
Convey("Use cache middleware", t, func() {
t := tango.Classic()
t.Use(New())
t.Get("/", new(testCacheController))
resp := httptest.NewRecorder()
req, err := http.NewRequest("GET", "/", nil)
So(err, ShouldBeNil)
t.ServeHTTP(resp, req)
})
Convey("Register invalid adapter", t, func() {
Convey("Adatper not exists", func() {
defer func() {
So(recover(), ShouldNotBeNil)
}()
t := tango.Classic()
t.Use(New(Options{
Adapter: "fake",
}))
})
Convey("Provider value is nil", func() {
defer func() {
So(recover(), ShouldNotBeNil)
}()
Register("fake", nil)
})
Convey("Register twice", func() {
defer func() {
So(recover(), ShouldNotBeNil)
}()
Register("memory", &MemoryCacher{})
})
})
}
示例7: TestValue
func TestValue(t *testing.T) {
Convey("steps method", t, func() {
tasks := readBook(".files/1st.yaml")
steps := tasks[0].Series
fmt.Println(tasks[0].Name)
So(steps, ShouldNotBeNil)
So(len(steps), ShouldEqual, 2)
})
Convey("book steps has specific type", t, func() {
tasks := readBook(".files/1st.yaml")
steps := tasks[0].Parallel
So(steps, ShouldNotBeNil)
So(len(steps), ShouldEqual, 0)
})
Convey("walking path produces value", t, func() {
a := make(map[string]interface{})
a["stuff"] = "where"
b := make(map[string]interface{})
b["here"] = a
u := NewValue(b)
u = u.To("here.stuff")
So(u.ToString(), ShouldEqual, "where")
})
Convey("should get the 'here' value from the map", t, func() {
m := make(map[string]string)
m["here"] = "there"
t := NewValue(m)
t = t.Get("here")
So(t.HasValue(), ShouldBeTrue)
So(t.IsMap(), ShouldBeFalse)
So(t.ToString(), ShouldEqual, "there")
})
Convey("using a path to a value that EXISTS should produce that value", t, func() {
m := createMap()
t := NewValue(m)
t = t.Get("here")
So(t.HasValue(), ShouldBeTrue)
So(t.IsMap(), ShouldBeFalse)
So(t.ToInt(), ShouldEqual, 1)
})
Convey("converting with just key", t, func() {
m := make(map[string]string)
m["here"] = "stuff"
h := reflect.ValueOf("here")
actual := reflect.ValueOf(m).MapIndex(h)
val := actual.Interface()
So(val, ShouldEqual, "stuff")
})
Convey("should be true that Value with 1 has a Value and that value is not a map", t, func() {
t := NewValue(1)
So(t.HasValue(), ShouldBeTrue)
So(t.IsMap(), ShouldBeFalse)
})
Convey("should be true that Value with 1 has a Value and that value is not a map", t, func() {
types := []interface{}{
make(map[string]string),
make(map[string]int),
make(map[string]interface{}),
make(map[interface{}]interface{}),
}
for _, k := range types {
t := NewValue(k)
So(t.HasValue(), ShouldBeTrue)
isMap := t.IsMap()
if !isMap {
dumpType(k)
}
So(isMap, ShouldBeTrue)
}
})
Convey("using a path to a value that DOESN'T exist should produce nil value", t, func() {
m := createMap()
t := NewValue(m)
t = t.Get("nope")
So(t.HasValue(), ShouldBeFalse)
So(t.IsMap(), ShouldBeFalse)
})
Convey("a map backed Value should return true for isMap", t, func() {
m := createMap()
t := NewValue(m)
So(t.IsMap(), ShouldBeTrue)
})
Convey("a map backed Value should have a 'value'", t, func() {
m := createMap()
t := NewValue(m)
So(t.values, ShouldNotBeNil)
So(t.HasValue(), ShouldBeTrue)
//.........这里部分代码省略.........