more e2e test cases (#2450)

This commit is contained in:
fatedier
2021-06-18 16:48:36 +08:00
committed by GitHub
parent c7d4637382
commit 900454e58b
45 changed files with 1736 additions and 1953 deletions

View File

@@ -0,0 +1,86 @@
package httpserver
import (
"fmt"
"net"
"net/http"
"strconv"
)
type Server struct {
bindAddr string
bindPort int
hanlder http.Handler
l net.Listener
hs *http.Server
}
type Option func(*Server) *Server
func New(options ...Option) *Server {
s := &Server{
bindAddr: "127.0.0.1",
}
for _, option := range options {
s = option(s)
}
return s
}
func WithBindAddr(addr string) Option {
return func(s *Server) *Server {
s.bindAddr = addr
return s
}
}
func WithBindPort(port int) Option {
return func(s *Server) *Server {
s.bindPort = port
return s
}
}
func WithHandler(h http.Handler) Option {
return func(s *Server) *Server {
s.hanlder = h
return s
}
}
func (s *Server) Run() error {
if err := s.initListener(); err != nil {
return err
}
addr := net.JoinHostPort(s.bindAddr, strconv.Itoa(s.bindPort))
hs := &http.Server{
Addr: addr,
Handler: s.hanlder,
}
s.hs = hs
go hs.Serve(s.l)
return nil
}
func (s *Server) Close() error {
if s.hs != nil {
return s.hs.Close()
}
return nil
}
func (s *Server) initListener() (err error) {
s.l, err = net.Listen("tcp", fmt.Sprintf("%s:%d", s.bindAddr, s.bindPort))
return
}
func (s *Server) BindAddr() string {
return s.bindAddr
}
func (s *Server) BindPort() int {
return s.bindPort
}

View File

@@ -0,0 +1,8 @@
package server
type Server interface {
Run() error
Close() error
BindAddr() string
BindPort() int
}

View File

@@ -1,4 +1,4 @@
package server
package streamserver
import (
"fmt"
@@ -7,16 +7,16 @@ import (
libnet "github.com/fatedier/frp/pkg/util/net"
)
type ServerType string
type Type string
const (
TCP ServerType = "tcp"
UDP ServerType = "udp"
Unix ServerType = "unix"
TCP Type = "tcp"
UDP Type = "udp"
Unix Type = "unix"
)
type Server struct {
netType ServerType
netType Type
bindAddr string
bindPort int
respContent []byte
@@ -29,7 +29,7 @@ type Server struct {
type Option func(*Server) *Server
func New(netType ServerType, options ...Option) *Server {
func New(netType Type, options ...Option) *Server {
s := &Server{
netType: netType,
bindAddr: "127.0.0.1",