當前位置: 首頁>>代碼示例>>Golang>>正文


Golang T.ServeHTTP方法代碼示例

本文整理匯總了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)
		})
	})
}
開發者ID:tango-contrib,項目名稱:cache-ledis,代碼行數:28,代碼來源:ledis_test.go

示例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)
		})
	})
}
開發者ID:tango-contrib,項目名稱:cache-postgres,代碼行數:28,代碼來源:postgres_test.go

示例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)
		})
	})
}
開發者ID:tango-contrib,項目名稱:cache-memcache,代碼行數:31,代碼來源:memcache_test.go

示例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)
		})
	})
}
開發者ID:tango-contrib,項目名稱:cache-redis,代碼行數:30,代碼來源:redis_test.go

示例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{})
		})
	})
}
開發者ID:tango-contrib,項目名稱:cache,代碼行數:41,代碼來源:cache_test.go


注:本文中的testing.T.ServeHTTP方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。