-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
69 lines (54 loc) · 1.49 KB
/
main_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"bytes"
"os"
"os/exec"
"strings"
"testing"
"time"
)
func TestInvalidProxyAddress(t *testing.T) {
executer := DefaultExecuter{}
err := executer.ExecuteCommand("invalid-proxy-address", "echo", []string{"Hello World"})
if err == nil || !strings.Contains(err.Error(), "failed to connect to proxy") {
t.Errorf("Expected proxy connection failure, got %v", err)
}
}
func TestExecuteCommand_InvalidProxyAddress(t *testing.T) {
executer := DefaultExecuter{}
err := executer.ExecuteCommand("invalid-proxy", "echo", []string{"Hello World"})
if err == nil || !strings.Contains(err.Error(), "failed to connect to proxy") {
t.Errorf("Expected proxy connection failure, got %v", err)
}
}
func TestTerminateProcess(t *testing.T) {
cmd := exec.Command("sleep", "10")
if err := cmd.Start(); err != nil {
t.Fatalf("Failed to start process: %v", err)
}
if cmd.Process == nil {
t.Fatalf("Process was not started")
}
terminateProcess(cmd)
time.Sleep(time.Second)
if err := cmd.Process.Signal(nil); err == nil {
t.Errorf("Process was not terminated")
}
}
func TestClearLine(t *testing.T) {
r, w, err := os.Pipe()
if err != nil {
t.Fatalf("Failed to create pipe: %v", err)
}
oldStdout := os.Stdout
os.Stdout = w
defer func() { os.Stdout = oldStdout }()
clearLine()
w.Close()
var buf bytes.Buffer
buf.ReadFrom(r)
expected := "\r" + strings.Repeat(" ", 50) + "\n"
if got := buf.String(); got != expected {
t.Errorf("clearLine() = %q, want %q", got, expected)
}
}