1 В избранное 0 Ответвления 0

OSCHINA-MIRROR/lunny-tango

Присоединиться к Gitlife
Откройте для себя и примите участие в публичных проектах с открытым исходным кодом с участием более 10 миллионов разработчиков. Приватные репозитории также полностью бесплатны :)
Присоединиться бесплатно
Клонировать/Скачать
cookie_test.go 35 КБ
Копировать Редактировать Web IDE Исходные данные Просмотреть построчно История
Lunny Xiao Отправлено 07.03.2017 16:27 3388747
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673
// Copyright 2015 The Tango Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package tango
import (
"bytes"
"fmt"
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
)
func TestCookie1(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", func(ctx *Context) string {
ck := ctx.Cookies().Get("name")
if ck != nil {
return ck.Value
}
return ""
})
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("name", "test"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "test")
}
func TestCookie2(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", func(ctx *Context) string {
ctx.Cookies().Set(NewCookie("name", "test"))
return "test"
})
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "test")
expect(t, strings.Split(recorder.Header().Get("Set-Cookie"), ";")[0], "name=test")
}
func TestCookie3(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", func(ctx *Context) string {
ctx.Cookies().Expire("expire", time.Now())
return "test"
})
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("expire", "test"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "test")
fmt.Println(recorder.Header().Get("Set-Cookie"))
expect(t, strings.Split(recorder.Header().Get("Set-Cookie"), ";")[0], "expire=test")
}
func TestCookie4(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", func(ctx *Context) string {
ctx.Cookies().Del("ttttt")
return "test"
})
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("ttttt", "test"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "test")
//expect(t, recorder.Header().Get("Set-Cookie"), "ttttt=test; Max-Age=0")
}
func TestCookie5(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", func(ctx *Context) string {
ck := ctx.SecureCookies("sssss").Get("name")
if ck != nil {
return ck.Value
}
return ""
})
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie("sssss", "name", "test"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "test")
}
func TestCookie6(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", func(ctx *Context) string {
ctx.SecureCookies("ttttt").Set(NewSecureCookie("ttttt", "name", "test"))
return "test"
})
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "test")
r := strings.Split(recorder.Header().Get("Set-Cookie"), ";")[0]
s := strings.SplitN(r, "=", 2)
name, value := s[0], s[1]
expect(t, name, "name")
expect(t, parseSecureCookie("ttttt", value), "test")
}
func TestCookie7(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", func(ctx *Context) string {
ctx.SecureCookies("ttttt").Expire("expire", time.Now())
return "test"
})
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie("ttttt", "expire", "test"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "test")
expect(t, strings.Split(recorder.Header().Get("Set-Cookie"), "|")[0], "expire=test")
}
func TestCookie8(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", func(ctx *Context) string {
ctx.SecureCookies("ttttt").Del("ttttt")
return "test"
})
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie("ttttt", "ttttt", "test"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "test")
expect(t, strings.Split(recorder.Header().Get("Set-Cookie"), "|")[0], "ttttt=test")
}
type Cookie11Action struct {
Ctx
}
func (a *Cookie11Action) Get() string {
v, _ := a.Cookies().Int("test")
return fmt.Sprintf("%d", v)
}
func TestCookie11(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie11Action))
req, err := http.NewRequest("GET", "http://localhost:8000", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie12Action struct {
Ctx
}
func (a *Cookie12Action) Get() string {
v, _ := a.Cookies().Int32("test")
return fmt.Sprintf("%d", v)
}
func TestCookie12(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie12Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie13Action struct {
Ctx
}
func (a *Cookie13Action) Get() string {
v, _ := a.Cookies().Int64("test")
return fmt.Sprintf("%d", v)
}
func TestCookie13(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie13Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie14Action struct {
Ctx
}
func (a *Cookie14Action) Get() string {
v, _ := a.Cookies().Uint("test")
return fmt.Sprintf("%d", v)
}
func TestCookie14(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie14Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie15Action struct {
Ctx
}
func (a *Cookie15Action) Get() string {
v, _ := a.Cookies().Uint32("test")
return fmt.Sprintf("%d", v)
}
func TestCookie15(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie15Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie16Action struct {
Ctx
}
func (a *Cookie16Action) Get() string {
v, _ := a.Cookies().Uint64("test")
return fmt.Sprintf("%d", v)
}
func TestCookie16(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie16Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie17Action struct {
Ctx
}
func (a *Cookie17Action) Get() string {
v, _ := a.Cookies().Float32("test")
return fmt.Sprintf("%.2f", v)
}
func TestCookie17(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie17Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1.00")
}
type Cookie18Action struct {
Ctx
}
func (a *Cookie18Action) Get() string {
v, _ := a.Cookies().Float64("test")
return fmt.Sprintf("%.2f", v)
}
func TestCookie18(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie18Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1.00")
}
type Cookie19Action struct {
Ctx
}
func (a *Cookie19Action) Get() string {
v, _ := a.Cookies().Bool("test")
return fmt.Sprintf("%v", v)
}
func TestCookie19(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie19Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "true")
}
type Cookie20Action struct {
Ctx
}
func (a *Cookie20Action) Get() string {
v, _ := a.Cookies().String("test")
return fmt.Sprintf("%v", v)
}
func TestCookie20(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie20Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie21Action struct {
Ctx
}
func (a *Cookie21Action) Get() string {
v := a.Cookies().MustInt("test")
return fmt.Sprintf("%d", v)
}
func TestCookie21(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie21Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie22Action struct {
Ctx
}
func (a *Cookie22Action) Get() string {
v := a.Cookies().MustInt32("test")
return fmt.Sprintf("%d", v)
}
func TestCookie22(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie22Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie23Action struct {
Ctx
}
func (a *Cookie23Action) Get() string {
v := a.Cookies().MustInt64("test")
return fmt.Sprintf("%d", v)
}
func TestCookie23(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie23Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie24Action struct {
Ctx
}
func (a *Cookie24Action) Get() string {
v := a.Cookies().MustUint("test")
return fmt.Sprintf("%d", v)
}
func TestCookie24(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie24Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie25Action struct {
Ctx
}
func (a *Cookie25Action) Get() string {
v := a.Cookies().MustUint32("test")
return fmt.Sprintf("%d", v)
}
func TestCookie25(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie25Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie26Action struct {
Ctx
}
func (a *Cookie26Action) Get() string {
v := a.Cookies().MustUint64("test")
return fmt.Sprintf("%d", v)
}
func TestCookie26(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie26Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie27Action struct {
Ctx
}
func (a *Cookie27Action) Get() string {
v := a.Cookies().MustFloat32("test")
return fmt.Sprintf("%.2f", v)
}
func TestCookie27(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie27Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1.00")
}
type Cookie28Action struct {
Ctx
}
func (a *Cookie28Action) Get() string {
v := a.Cookies().MustFloat64("test")
return fmt.Sprintf("%.2f", v)
}
func TestCookie28(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie28Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1.00")
}
type Cookie29Action struct {
Ctx
}
func (a *Cookie29Action) Get() string {
v := a.Cookies().MustBool("test")
return fmt.Sprintf("%v", v)
}
func TestCookie29(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie29Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "true")
}
type Cookie30Action struct {
Ctx
}
func (a *Cookie30Action) Get() string {
v := a.Cookies().MustString("test")
return fmt.Sprintf("%s", v)
}
func TestCookie30(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie30Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
const (
secrectCookie = "ssss"
)
type Cookie31Action struct {
Ctx
}
func (a *Cookie31Action) Get() string {
v, _ := a.SecureCookies(secrectCookie).Int("test")
return fmt.Sprintf("%d", v)
}
func TestCookie31(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie31Action))
req, err := http.NewRequest("GET", "http://localhost:8000", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie32Action struct {
Ctx
}
func (a *Cookie32Action) Get() string {
v, _ := a.SecureCookies(secrectCookie).Int32("test")
return fmt.Sprintf("%d", v)
}
func TestCookie32(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie32Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie33Action struct {
Ctx
}
func (a *Cookie33Action) Get() string {
v, _ := a.SecureCookies(secrectCookie).Int64("test")
return fmt.Sprintf("%d", v)
}
func TestCookie33(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie33Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie34Action struct {
Ctx
}
func (a *Cookie34Action) Get() string {
v, _ := a.SecureCookies(secrectCookie).Uint("test")
return fmt.Sprintf("%d", v)
}
func TestCookie34(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie34Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie35Action struct {
Ctx
}
func (a *Cookie35Action) Get() string {
v, _ := a.SecureCookies(secrectCookie).Uint32("test")
return fmt.Sprintf("%d", v)
}
func TestCookie35(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie35Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie36Action struct {
Ctx
}
func (a *Cookie36Action) Get() string {
v, _ := a.SecureCookies(secrectCookie).Uint64("test")
return fmt.Sprintf("%d", v)
}
func TestCookie36(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie36Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie37Action struct {
Ctx
}
func (a *Cookie37Action) Get() string {
v, _ := a.SecureCookies(secrectCookie).Float32("test")
return fmt.Sprintf("%.2f", v)
}
func TestCookie37(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie37Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1.00")
}
type Cookie38Action struct {
Ctx
}
func (a *Cookie38Action) Get() string {
v, _ := a.SecureCookies(secrectCookie).Float64("test")
return fmt.Sprintf("%.2f", v)
}
func TestCookie38(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie38Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1.00")
}
type Cookie39Action struct {
Ctx
}
func (a *Cookie39Action) Get() string {
v, _ := a.SecureCookies(secrectCookie).Bool("test")
return fmt.Sprintf("%v", v)
}
func TestCookie39(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie39Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "true")
}
type Cookie40Action struct {
Ctx
}
func (a *Cookie40Action) Get() string {
v, _ := a.SecureCookies(secrectCookie).String("test")
return fmt.Sprintf("%v", v)
}
func TestCookie40(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie40Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie41Action struct {
Ctx
}
func (a *Cookie41Action) Get() string {
v := a.SecureCookies(secrectCookie).MustInt("test")
return fmt.Sprintf("%d", v)
}
func TestCookie41(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie41Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie42Action struct {
Ctx
}
func (a *Cookie42Action) Get() string {
v := a.SecureCookies(secrectCookie).MustInt32("test")
return fmt.Sprintf("%d", v)
}
func TestCookie42(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie42Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie43Action struct {
Ctx
}
func (a *Cookie43Action) Get() string {
v := a.SecureCookies(secrectCookie).MustInt64("test")
return fmt.Sprintf("%d", v)
}
func TestCookie43(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie43Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie44Action struct {
Ctx
}
func (a *Cookie44Action) Get() string {
v := a.SecureCookies(secrectCookie).MustUint("test")
return fmt.Sprintf("%d", v)
}
func TestCookie44(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie44Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie45Action struct {
Ctx
}
func (a *Cookie45Action) Get() string {
v := a.SecureCookies(secrectCookie).MustUint32("test")
return fmt.Sprintf("%d", v)
}
func TestCookie45(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie45Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie46Action struct {
Ctx
}
func (a *Cookie46Action) Get() string {
v := a.SecureCookies(secrectCookie).MustUint64("test")
return fmt.Sprintf("%d", v)
}
func TestCookie46(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie46Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie47Action struct {
Ctx
}
func (a *Cookie47Action) Get() string {
v := a.SecureCookies(secrectCookie).MustFloat32("test")
return fmt.Sprintf("%.2f", v)
}
func TestCookie47(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie47Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1.00")
}
type Cookie48Action struct {
Ctx
}
func (a *Cookie48Action) Get() string {
v := a.SecureCookies(secrectCookie).MustFloat64("test")
return fmt.Sprintf("%.2f", v)
}
func TestCookie48(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie48Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1.00")
}
type Cookie49Action struct {
Ctx
}
func (a *Cookie49Action) Get() string {
v := a.SecureCookies(secrectCookie).MustBool("test")
return fmt.Sprintf("%v", v)
}
func TestCookie49(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie49Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "true")
}
type Cookie50Action struct {
Ctx
}
func (a *Cookie50Action) Get() string {
v := a.SecureCookies(secrectCookie).MustString("test")
return fmt.Sprintf("%s", v)
}
func TestCookie50(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie50Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewSecureCookie(secrectCookie, "test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie51Action struct {
Ctx
}
func (a *Cookie51Action) Get() string {
v := a.CookieInt("test")
return fmt.Sprintf("%d", v)
}
func TestCookie51(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie51Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie52Action struct {
Ctx
}
func (a *Cookie52Action) Get() string {
v := a.CookieInt32("test")
return fmt.Sprintf("%d", v)
}
func TestCookie52(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie52Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie53Action struct {
Ctx
}
func (a *Cookie53Action) Get() string {
v := a.CookieInt64("test")
return fmt.Sprintf("%d", v)
}
func TestCookie53(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie53Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie54Action struct {
Ctx
}
func (a *Cookie54Action) Get() string {
v := a.CookieUint("test")
return fmt.Sprintf("%d", v)
}
func TestCookie54(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie54Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie55Action struct {
Ctx
}
func (a *Cookie55Action) Get() string {
v := a.CookieUint32("test")
return fmt.Sprintf("%d", v)
}
func TestCookie55(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie55Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie56Action struct {
Ctx
}
func (a *Cookie56Action) Get() string {
v := a.CookieUint64("test")
return fmt.Sprintf("%d", v)
}
func TestCookie56(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie56Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}
type Cookie57Action struct {
Ctx
}
func (a *Cookie57Action) Get() string {
v := a.CookieFloat32("test")
return fmt.Sprintf("%.2f", v)
}
func TestCookie57(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie57Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1.00")
}
type Cookie58Action struct {
Ctx
}
func (a *Cookie58Action) Get() string {
v := a.CookieFloat64("test")
return fmt.Sprintf("%.2f", v)
}
func TestCookie58(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie58Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1.00")
}
type Cookie59Action struct {
Ctx
}
func (a *Cookie59Action) Get() string {
v := a.CookieBool("test")
return fmt.Sprintf("%v", v)
}
func TestCookie59(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie59Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "true")
}
type Cookie60Action struct {
Ctx
}
func (a *Cookie60Action) Get() string {
v := a.Cookie("test")
return fmt.Sprintf("%s", v)
}
func TestCookie60(t *testing.T) {
buff := bytes.NewBufferString("")
recorder := httptest.NewRecorder()
recorder.Body = buff
o := Classic()
o.Get("/", new(Cookie60Action))
req, err := http.NewRequest("GET", "http://localhost:8000/", nil)
if err != nil {
t.Error(err)
}
req.AddCookie(NewCookie("test", "1"))
o.ServeHTTP(recorder, req)
expect(t, recorder.Code, http.StatusOK)
refute(t, len(buff.String()), 0)
expect(t, buff.String(), "1")
}

Опубликовать ( 0 )

Вы можете оставить комментарий после Вход в систему

1
https://api.gitlife.ru/oschina-mirror/lunny-tango.git
git@api.gitlife.ru:oschina-mirror/lunny-tango.git
oschina-mirror
lunny-tango
lunny-tango
master