本文整理汇总了Golang中testing.T.ServeHTTP方法的典型用法代码示例。如果您正苦于以下问题:Golang T.ServeHTTP方法的具体用法?Golang T.ServeHTTP怎么用?Golang T.ServeHTTP使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类testing.T
的用法示例。
在下文中一共展示了T.ServeHTTP方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: 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)
})
})
}
示例2: 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)
})
})
}
示例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: 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{})
})
})
}