准备测试环境代码
This commit is contained in:
294
server/fwd/service_test.go
Normal file
294
server/fwd/service_test.go
Normal file
@@ -0,0 +1,294 @@
|
||||
package fwd
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"io"
|
||||
"net"
|
||||
"proxy-server/pkg/utils"
|
||||
"proxy-server/server/pkg/socks5"
|
||||
"reflect"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
type args struct {
|
||||
config *Config
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want *Service
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
{
|
||||
name: "server config nil",
|
||||
args: args{
|
||||
config: nil,
|
||||
},
|
||||
want: &Service{
|
||||
Config: &Config{},
|
||||
},
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
if got := New(tt.args.config); !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("New() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNoAuthAuthenticator_Authenticate(t *testing.T) {
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
reader io.Reader
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantWriter string
|
||||
want *socks5.AuthContext
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
a := &NoAuthAuthenticator{}
|
||||
writer := &bytes.Buffer{}
|
||||
got, err := a.Authenticate(tt.args.ctx, tt.args.reader, writer)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("Authenticate() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if gotWriter := writer.String(); gotWriter != tt.wantWriter {
|
||||
t.Errorf("Authenticate() gotWriter = %v, want %v", gotWriter, tt.wantWriter)
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("Authenticate() got = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestNoAuthAuthenticator_Method(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
want socks5.AuthMethod
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
a := &NoAuthAuthenticator{}
|
||||
if got := a.Method(); got != tt.want {
|
||||
t.Errorf("Method() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestService_Run(t *testing.T) {
|
||||
type fields struct {
|
||||
Config *Config
|
||||
connMap map[string]socks5.ProxyData
|
||||
ctrlConnWg utils.CountWaitGroup
|
||||
dataConnWg utils.CountWaitGroup
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
errCh chan error
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := &Service{
|
||||
Config: tt.fields.Config,
|
||||
connMap: tt.fields.connMap,
|
||||
ctrlConnWg: tt.fields.ctrlConnWg,
|
||||
dataConnWg: tt.fields.dataConnWg,
|
||||
}
|
||||
s.Run(tt.args.ctx, tt.args.errCh)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestService_processCtrlConn(t *testing.T) {
|
||||
type fields struct {
|
||||
Config *Config
|
||||
connMap map[string]socks5.ProxyData
|
||||
ctrlConnWg utils.CountWaitGroup
|
||||
dataConnWg utils.CountWaitGroup
|
||||
}
|
||||
type args struct {
|
||||
controller net.Conn
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := &Service{
|
||||
Config: tt.fields.Config,
|
||||
connMap: tt.fields.connMap,
|
||||
ctrlConnWg: tt.fields.ctrlConnWg,
|
||||
dataConnWg: tt.fields.dataConnWg,
|
||||
}
|
||||
s.processCtrlConn(tt.args.controller)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestService_processDataConn(t *testing.T) {
|
||||
type fields struct {
|
||||
Config *Config
|
||||
connMap map[string]socks5.ProxyData
|
||||
ctrlConnWg utils.CountWaitGroup
|
||||
dataConnWg utils.CountWaitGroup
|
||||
}
|
||||
type args struct {
|
||||
client net.Conn
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := &Service{
|
||||
Config: tt.fields.Config,
|
||||
connMap: tt.fields.connMap,
|
||||
ctrlConnWg: tt.fields.ctrlConnWg,
|
||||
dataConnWg: tt.fields.dataConnWg,
|
||||
}
|
||||
s.processDataConn(tt.args.client)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestService_startCtrlTun(t *testing.T) {
|
||||
type fields struct {
|
||||
Config *Config
|
||||
connMap map[string]socks5.ProxyData
|
||||
ctrlConnWg utils.CountWaitGroup
|
||||
dataConnWg utils.CountWaitGroup
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
errCh chan error
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := &Service{
|
||||
Config: tt.fields.Config,
|
||||
connMap: tt.fields.connMap,
|
||||
ctrlConnWg: tt.fields.ctrlConnWg,
|
||||
dataConnWg: tt.fields.dataConnWg,
|
||||
}
|
||||
s.startCtrlTun(tt.args.ctx, tt.args.errCh)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestService_startDataTun(t *testing.T) {
|
||||
type fields struct {
|
||||
Config *Config
|
||||
connMap map[string]socks5.ProxyData
|
||||
ctrlConnWg utils.CountWaitGroup
|
||||
dataConnWg utils.CountWaitGroup
|
||||
}
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
errCh chan error
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
fields fields
|
||||
args args
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
s := &Service{
|
||||
Config: tt.fields.Config,
|
||||
connMap: tt.fields.connMap,
|
||||
ctrlConnWg: tt.fields.ctrlConnWg,
|
||||
dataConnWg: tt.fields.dataConnWg,
|
||||
}
|
||||
s.startDataTun(tt.args.ctx, tt.args.errCh)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUserPassAuthenticator_Authenticate(t *testing.T) {
|
||||
type args struct {
|
||||
ctx context.Context
|
||||
reader io.Reader
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
wantWriter string
|
||||
want *socks5.AuthContext
|
||||
wantErr bool
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
a := &UserPassAuthenticator{}
|
||||
writer := &bytes.Buffer{}
|
||||
got, err := a.Authenticate(tt.args.ctx, tt.args.reader, writer)
|
||||
if (err != nil) != tt.wantErr {
|
||||
t.Errorf("Authenticate() error = %v, wantErr %v", err, tt.wantErr)
|
||||
return
|
||||
}
|
||||
if gotWriter := writer.String(); gotWriter != tt.wantWriter {
|
||||
t.Errorf("Authenticate() gotWriter = %v, want %v", gotWriter, tt.wantWriter)
|
||||
}
|
||||
if !reflect.DeepEqual(got, tt.want) {
|
||||
t.Errorf("Authenticate() got = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestUserPassAuthenticator_Method(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
want socks5.AuthMethod
|
||||
}{
|
||||
// TODO: Add test cases.
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
a := &UserPassAuthenticator{}
|
||||
if got := a.Method(); got != tt.want {
|
||||
t.Errorf("Method() = %v, want %v", got, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user