131 lines
2.1 KiB
Go
131 lines
2.1 KiB
Go
// Copyright 2021 Liuxiangchao iwind.liu@gmail.com. All rights reserved.
|
|
|
|
package js_test
|
|
|
|
import (
|
|
"github.com/iwind/TeaGo/maps"
|
|
"github.com/iwind/TeaGo/types"
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
type FakeRequest struct {
|
|
host string
|
|
remoteAddr string
|
|
header http.Header
|
|
uri string
|
|
}
|
|
|
|
func (this *FakeRequest) Id() string {
|
|
return types.String(time.Now().UnixMicro())
|
|
}
|
|
|
|
func (this *FakeRequest) Server() maps.Map {
|
|
return maps.Map{"id": 123}
|
|
}
|
|
|
|
func (this *FakeRequest) Node() maps.Map {
|
|
return maps.Map{"id": 456}
|
|
}
|
|
|
|
func (this *FakeRequest) URL() string {
|
|
return "https://example.com/hello?name=Lily"
|
|
}
|
|
|
|
func (this *FakeRequest) Path() string {
|
|
return "/hello"
|
|
}
|
|
|
|
func (this *FakeRequest) URI() string {
|
|
return this.uri
|
|
}
|
|
|
|
func (this *FakeRequest) SetURI(uri string) {
|
|
this.uri = uri
|
|
}
|
|
|
|
func (this *FakeRequest) Host() string {
|
|
return this.host
|
|
}
|
|
|
|
func (this *FakeRequest) RemoteAddr() string {
|
|
return this.remoteAddr
|
|
}
|
|
|
|
func (this *FakeRequest) RawRemoteAddr() string {
|
|
return "127.0.0.1:12345"
|
|
}
|
|
|
|
func (this *FakeRequest) RemotePort() int {
|
|
return 80
|
|
}
|
|
|
|
func (this *FakeRequest) Method() string {
|
|
return http.MethodGet
|
|
}
|
|
|
|
func (this *FakeRequest) ContentLength() int64 {
|
|
return 1024
|
|
}
|
|
func (this *FakeRequest) TransferEncoding() string {
|
|
return "gzip"
|
|
}
|
|
|
|
func (this *FakeRequest) Proto() string {
|
|
return "HTTP/1.2"
|
|
}
|
|
|
|
func (this *FakeRequest) ProtoMajor() int {
|
|
return 1
|
|
}
|
|
|
|
func (this *FakeRequest) ProtoMinor() int {
|
|
return 2
|
|
}
|
|
|
|
func (this *FakeRequest) Cookie(name string) string {
|
|
return "cookie"
|
|
}
|
|
|
|
func (this *FakeRequest) Header() http.Header {
|
|
return this.header
|
|
}
|
|
|
|
func (this *FakeRequest) SetHeader(name string, values []string) {
|
|
if this.header == nil {
|
|
this.header = http.Header{}
|
|
}
|
|
this.header[name] = values
|
|
}
|
|
|
|
func (this *FakeRequest) DeleteHeader(name string) {
|
|
if this.header == nil {
|
|
return
|
|
}
|
|
delete(this.header, name)
|
|
}
|
|
|
|
func (this *FakeRequest) SetAttr(name string, value string) {
|
|
|
|
}
|
|
|
|
func (this *FakeRequest) SetVar(name string, value string) {
|
|
|
|
}
|
|
|
|
func (this *FakeRequest) Format(s string) string {
|
|
return s
|
|
}
|
|
|
|
func (this *FakeRequest) Done() {
|
|
|
|
}
|
|
|
|
func (this *FakeRequest) Allow() {
|
|
|
|
}
|
|
|
|
func (this *FakeRequest) Close() {
|
|
|
|
}
|