-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain_test.go
More file actions
67 lines (60 loc) · 1.61 KB
/
main_test.go
File metadata and controls
67 lines (60 loc) · 1.61 KB
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
package main
import (
"testing"
)
func TestFlags(t *testing.T) {
// Test default values
if domainFlag != "example.com" {
t.Errorf("Expected default domain 'example.com', got '%s'", domainFlag)
}
if ipOnlyFlag != false {
t.Errorf("Expected default ipOnly false, got %v", ipOnlyFlag)
}
if debugFlag != false {
t.Errorf("Expected default debug false, got %v", debugFlag)
}
// Test setting flags
domainFlag = "test.com"
ipOnlyFlag = true
debugFlag = true
if domainFlag != "test.com" {
t.Errorf("Expected domain 'test.com', got '%s'", domainFlag)
}
if !ipOnlyFlag {
t.Errorf("Expected ipOnly to be true")
}
if !debugFlag {
t.Errorf("Expected debug to be true")
}
}
func TestFindDefaultNetworkInterface(t *testing.T) {
iface, err := findDefaultNetworkInterface()
if err != nil {
t.Fatalf("Error finding default network interface: %v", err)
}
if iface == nil {
t.Fatal("Expected a valid network interface, got nil")
}
// Check that the interface has a valid name
if iface.Name == "" {
t.Errorf("Expected a valid interface name, got an empty string")
}
}
func TestGetDefaultNetworkInterface(t *testing.T) {
iface := getDefaultNetworkInterface(true, nil)
if iface == nil {
t.Fatalf("Expected a network interface, got nil")
}
// Check that the interface has a valid name
if iface.Name == "" {
t.Errorf("Expected a valid interface name, got an empty string")
}
}
// To test isRoot, you should run the test manually with and without root privileges.
func TestIsRootManual(t *testing.T) {
if isRoot() {
t.Log("Test is running as root")
} else {
t.Log("Test is running as a non-root user")
}
}