Repository navigation
Expand file tree
/
Copy pathmain_test.go
More file actions
187 lines (152 loc) · 3.91 KB
/
Copy pathmain_test.go
File metadata and controls
187 lines (152 loc) · 3.91 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
package main
import (
"testing"
"github.com/moby/moby/api/types/container"
internalContainer "ldddns.arnested.dk/internal/container"
)
func createTestContainer(labels map[string]string) internalContainer.Container {
return internalContainer.Container{
ID: "test-container",
Config: &container.Config{
Labels: labels,
},
}
}
func TestIgnoreOneoffEnabled(t *testing.T) {
t.Parallel()
tests := []struct {
name string
labels map[string]string
expectIgnore bool
}{
{
name: "oneoff is True",
labels: map[string]string{
"com.docker.compose.oneoff": "True",
},
expectIgnore: true,
},
{
name: "oneoff is False",
labels: map[string]string{
"com.docker.compose.oneoff": "False",
},
expectIgnore: false,
},
{
name: "oneoff label missing",
labels: map[string]string{},
expectIgnore: false,
},
{
name: "oneoff with unexpected value",
labels: map[string]string{
"com.docker.compose.oneoff": "yes",
},
expectIgnore: false,
},
}
config := Config{IgnoreDockerComposeOneoff: true}
for _, testCase := range tests {
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()
containerInfo := createTestContainer(testCase.labels)
result := ignoreOneoff(containerInfo, config)
if result != testCase.expectIgnore {
t.Errorf("Expected ignoreOneoff to return %v, got %v", testCase.expectIgnore, result)
}
})
}
}
func TestIgnoreOneoffDisabled(t *testing.T) {
t.Parallel()
tests := []struct {
name string
labels map[string]string
}{
{
name: "oneoff is True",
labels: map[string]string{
"com.docker.compose.oneoff": "True",
},
},
{
name: "oneoff is False",
labels: map[string]string{
"com.docker.compose.oneoff": "False",
},
},
}
config := Config{IgnoreDockerComposeOneoff: false}
for _, testCase := range tests {
t.Run(testCase.name, func(t *testing.T) {
t.Parallel()
containerInfo := createTestContainer(testCase.labels)
result := ignoreOneoff(containerInfo, config)
if result {
t.Error("Expected ignoreOneoff to return false when disabled")
}
})
}
}
func TestGetVersion(t *testing.T) {
t.Parallel()
// Test that getVersion returns a non-empty string
version := getVersion()
if version == "" {
t.Error("Expected getVersion to return non-empty string")
}
}
func TestGops(t *testing.T) {
t.Parallel()
// Test that gops with start=false doesn't panic
gops(false)
// We can't easily test start=true without actually starting the agent
// which could conflict with other tests or require cleanup
}
func TestNewEntryGroups(t *testing.T) {
t.Parallel()
// Test that newEntryGroups creates a valid entryGroups instance
// We pass nil since we're just testing the constructor logic
egs := newEntryGroups(nil)
if egs == nil {
t.Fatal("Expected newEntryGroups to return non-nil")
}
if egs.groups == nil {
t.Error("Expected groups map to be initialized")
}
if egs.avahiServer != nil {
t.Error("Expected avahiServer to be nil when passed nil")
}
}
func TestConstants(t *testing.T) {
t.Parallel()
// Test that constants are set correctly
if tld != "local" {
t.Errorf("Expected tld to be 'local', got %q", tld)
}
}
func TestEntryGroupsWithoutGroup(t *testing.T) {
t.Parallel()
egs := newEntryGroups(nil)
// get without create must not create a group, and commit must release
// the lock.
entryGroup, commit, err := egs.get("unknown", false)
commit()
if err != nil {
t.Fatalf("Expected no error, got %v", err)
}
if entryGroup != nil {
t.Error("Expected no entry group for an unknown container")
}
if len(egs.groups) != 0 {
t.Error("Expected get without create to leave the groups map empty")
}
// free of an unknown container must do nothing. It must not call the
// nil Avahi server.
egs.free("unknown")
err = resetContainer(egs, "unknown")
if err != nil {
t.Errorf("Expected no error resetting an unknown container, got %v", err)
}
}