You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

67 lines
1.2 KiB

package client
import (
"os"
"testing"
)
func TestNewClient(t *testing.T) {
client := NewClient("http")
if client == nil {
t.Fatal("NewClient returned nil")
}
if client.mode != "http" {
t.Errorf("Expected mode 'http', got '%s'", client.mode)
}
if client.systemProxyMgr == nil {
t.Error("SystemProxyManager should be initialized")
}
}
func TestClientStart_InvalidConfig(t *testing.T) {
client := NewClient("http")
// 测试不存在的配置文件
err := client.Start("nonexistent.yaml")
if err == nil {
t.Error("Expected error for nonexistent config file")
}
}
func TestClientStart_InvalidMode(t *testing.T) {
// 创建临时配置文件
tmpFile, err := os.CreateTemp("", "test_config_*.yaml")
if err != nil {
t.Fatal(err)
}
defer os.Remove(tmpFile.Name())
// 写入基本配置
configContent := `
serviceType: client
server:
address: 127.0.0.1
port: 1080
username: test
password: test
proxy:
mode: http
localPort: 8080
logLevel: info
timeout: 30s
`
if _, err := tmpFile.WriteString(configContent); err != nil {
t.Fatal(err)
}
tmpFile.Close()
// 测试无效模式
client := NewClient("invalid_mode")
err = client.Start(tmpFile.Name())
if err == nil {
t.Error("Expected error for invalid mode")
}
}