Skip to content

Commit f5fc04f

Browse files
committed
gofmt -w ./
1 parent 0dd2cd3 commit f5fc04f

21 files changed

Lines changed: 105 additions & 113 deletions

internal/config/config_test.go

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ func TestValidationErrors(t *testing.T) {
2222
t.Run("single validation error", func(t *testing.T) {
2323
ve := &ValidationErrors{}
2424
ve.Add(fmt.Errorf("test error"))
25-
25+
2626
if !ve.HasErrors() {
2727
t.Error("Expected errors")
2828
}
@@ -35,11 +35,11 @@ func TestValidationErrors(t *testing.T) {
3535
ve := &ValidationErrors{}
3636
ve.Add(fmt.Errorf("error 1"))
3737
ve.Add(fmt.Errorf("error 2"))
38-
38+
3939
if !ve.HasErrors() {
4040
t.Error("Expected errors")
4141
}
42-
42+
4343
expected := "multiple validation errors: error 1; error 2"
4444
if ve.Error() != expected {
4545
t.Errorf("Expected '%s', got %s", expected, ve.Error())
@@ -49,7 +49,7 @@ func TestValidationErrors(t *testing.T) {
4949
t.Run("add nil error should be ignored", func(t *testing.T) {
5050
ve := &ValidationErrors{}
5151
ve.Add(nil)
52-
52+
5353
if ve.HasErrors() {
5454
t.Error("Expected no errors when adding nil")
5555
}
@@ -67,12 +67,12 @@ func TestConfigValidate(t *testing.T) {
6767
t.Run("invalid default prober", func(t *testing.T) {
6868
cfg := DefaultConfig()
6969
cfg.Default = "nonexistent"
70-
70+
7171
err := cfg.Validate()
7272
if err == nil {
7373
t.Error("Expected validation error for invalid default prober")
7474
}
75-
75+
7676
if !strings.Contains(err.Error(), "default prober 'nonexistent' not found") {
7777
t.Errorf("Expected error about nonexistent default prober, got: %v", err)
7878
}
@@ -86,12 +86,12 @@ func TestConfigValidate(t *testing.T) {
8686
ExpectCodes: "invalid-pattern",
8787
},
8888
}
89-
89+
9090
err := cfg.Validate()
9191
if err == nil {
9292
t.Error("Expected validation error for invalid prober config")
9393
}
94-
94+
9595
if !strings.Contains(err.Error(), "prober 'invalid'") {
9696
t.Errorf("Expected error about invalid prober, got: %v", err)
9797
}
@@ -114,12 +114,12 @@ func TestConfigValidate(t *testing.T) {
114114
Port: 53,
115115
},
116116
}
117-
117+
118118
err := cfg.Validate()
119119
if err == nil {
120120
t.Error("Expected validation errors")
121121
}
122-
122+
123123
errMsg := err.Error()
124124
if !strings.Contains(errMsg, "multiple validation errors") {
125125
t.Errorf("Expected multiple validation errors message, got: %v", err)
@@ -132,7 +132,7 @@ func TestConfigValidate(t *testing.T) {
132132
t.Run("empty default prober should be valid", func(t *testing.T) {
133133
cfg := DefaultConfig()
134134
cfg.Default = ""
135-
135+
136136
if err := cfg.Validate(); err != nil {
137137
t.Errorf("Empty default prober should be valid: %v", err)
138138
}
@@ -182,7 +182,7 @@ prober:
182182
if err == nil {
183183
t.Error("Invalid config should fail validation")
184184
}
185-
185+
186186
if !strings.Contains(err.Error(), "invalid TOS value") {
187187
t.Errorf("Expected TOS validation error, got: %v", err)
188188
}
@@ -201,7 +201,7 @@ prober:
201201
if err == nil {
202202
t.Error("Invalid HTTP config should fail validation")
203203
}
204-
204+
205205
if !strings.Contains(err.Error(), "invalid expect_codes pattern") {
206206
t.Errorf("Expected expect_codes validation error, got: %v", err)
207207
}
@@ -222,9 +222,9 @@ prober:
222222
if err == nil {
223223
t.Error("Invalid DNS config should fail validation")
224224
}
225-
225+
226226
if !strings.Contains(err.Error(), "DNS server is required") {
227227
t.Errorf("Expected DNS server validation error, got: %v", err)
228228
}
229229
})
230-
}
230+
}

internal/prober/accept_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func TestHTTPProberAccept(t *testing.T) {
105105
prefix: "my-https",
106106
config: &HTTPConfig{
107107
ExpectCodes: "200",
108-
TLS: &TLSConfig{SkipVerify: true},
108+
TLS: &TLSConfig{SkipVerify: true},
109109
},
110110
target: "my-https://secure.example.com",
111111
},

internal/prober/code_matcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,4 @@ func isValidSinglePattern(pattern string) bool {
100100
// Single code pattern
101101
_, err := strconv.Atoi(pattern)
102102
return err == nil
103-
}
103+
}

internal/prober/code_matcher_test.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,9 @@ func TestMatchCode(t *testing.T) {
185185
for _, tt := range tests {
186186
t.Run(tt.name, func(t *testing.T) {
187187
result := MatchCode(tt.code, tt.pattern)
188-
188+
189189
if result != tt.expected {
190-
t.Errorf("Pattern %q with code %d: expected %v, got %v",
190+
t.Errorf("Pattern %q with code %d: expected %v, got %v",
191191
tt.pattern, tt.code, tt.expected, result)
192192
}
193193
})
@@ -220,12 +220,11 @@ func TestIsValidCodePattern(t *testing.T) {
220220
for _, tt := range tests {
221221
t.Run(tt.name, func(t *testing.T) {
222222
result := IsValidCodePattern(tt.pattern)
223-
223+
224224
if result != tt.expected {
225-
t.Errorf("Pattern %q validation: expected %v, got %v",
225+
t.Errorf("Pattern %q validation: expected %v, got %v",
226226
tt.pattern, tt.expected, result)
227227
}
228228
})
229229
}
230230
}
231-

internal/prober/details.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,4 +45,4 @@ type NTPDetails struct {
4545
Stratum int `json:"stratum"`
4646
Offset int64 `json:"offset_microseconds"` // In microseconds
4747
Precision int `json:"precision"`
48-
}
48+
}

internal/prober/dns.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func (p *DNSProber) success(result chan *Event, target *DNSTarget, sentTime time
267267
for _, ans := range resp.Answer {
268268
answers = append(answers, ans.String())
269269
}
270-
270+
271271
details := &ProbeDetails{
272272
ProbeType: "dns",
273273
DNS: &DNSDetails{
@@ -281,7 +281,7 @@ func (p *DNSProber) success(result chan *Event, target *DNSTarget, sentTime time
281281
UseTCP: target.UseTCP,
282282
},
283283
}
284-
284+
285285
result <- &Event{
286286
Key: target.OriginalTarget,
287287
DisplayName: target.OriginalTarget,

internal/prober/http.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
"strings"
1313
"sync"
1414
"time"
15-
1615
)
1716

1817
const (
@@ -189,19 +188,19 @@ func (p *HTTPProber) probe(r chan *Event, target string) {
189188
headers[key] = values[0] // Get only the first value
190189
}
191190
}
192-
191+
193192
var redirects []string
194193
if resp.Request.URL.String() != target {
195194
redirects = append(redirects, resp.Request.URL.String())
196195
}
197-
196+
198197
var probeType string
199198
if strings.HasPrefix(target, "https://") {
200199
probeType = "https"
201200
} else {
202201
probeType = "http"
203202
}
204-
203+
205204
details := &ProbeDetails{
206205
ProbeType: probeType,
207206
HTTP: &HTTPDetails{
@@ -211,7 +210,7 @@ func (p *HTTPProber) probe(r chan *Event, target string) {
211210
Redirects: redirects,
212211
},
213212
}
214-
213+
215214
r <- &Event{
216215
Key: target,
217216
DisplayName: target,

internal/prober/http_status_test.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,11 @@ func TestHTTPStatusCodeMatching(t *testing.T) {
178178
t.Run(tt.name, func(t *testing.T) {
179179
prober := NewHTTPProber(tt.config, "test")
180180
result := prober.isExpectedStatusCode(tt.statusCode)
181-
181+
182182
if result != tt.expected {
183-
t.Errorf("Expected %v, got %v for status code %d with config %+v",
183+
t.Errorf("Expected %v, got %v for status code %d with config %+v",
184184
tt.expected, result, tt.statusCode, tt.config)
185185
}
186186
})
187187
}
188188
}
189-

internal/prober/icmp.go

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ func (p *ICMPProber) success(r chan *Event, runCnt int, addr string, payload icm
190190

191191
// Extract detailed packet information
192192
icmpDetails := p.extractICMPDetails(runCnt, addr, payload, packetData, packetSize)
193-
193+
194194
// Create ICMP detail information
195195
details := &ProbeDetails{
196196
ProbeType: string(p.version),
@@ -213,21 +213,20 @@ func (p *ICMPProber) success(r chan *Event, runCnt int, addr string, payload icm
213213
func (p *ICMPProber) extractICMPDetails(runCnt int, addr string, payload icmp.Message, packetData []byte, packetSize int) *ICMPDetails {
214214
var payloadContent string
215215
var checksum uint16
216-
216+
217217
// Extract echo data if available
218218
if echoBody, ok := payload.Body.(*icmp.Echo); ok {
219-
219+
220220
// Format payload content with length limit
221221
payloadContent = formatPayloadContent(echoBody.Data)
222222
}
223-
223+
224224
// Extract checksum from raw packet data if available
225225
// ICMP checksum is at offset 2-3 in the ICMP header
226226
if len(packetData) >= 4 {
227227
checksum = binary.BigEndian.Uint16(packetData[2:4])
228228
}
229-
230-
229+
231230
// Convert ICMP type to int safely
232231
var icmpType int
233232
switch payload.Type {
@@ -243,7 +242,7 @@ func (p *ICMPProber) extractICMPDetails(runCnt int, addr string, payload icmp.Me
243242
icmpType = -1 // Unknown type
244243
}
245244
}
246-
245+
247246
details := &ICMPDetails{
248247
Sequence: runCnt,
249248
PacketSize: packetSize,
@@ -252,20 +251,18 @@ func (p *ICMPProber) extractICMPDetails(runCnt int, addr string, payload icmp.Me
252251
Checksum: checksum,
253252
Payload: payloadContent,
254253
}
255-
254+
256255
return details
257256
}
258257

259-
260-
261258
// formatPayloadContent formats payload bytes for display with length limit
262259
func formatPayloadContent(data []byte) string {
263260
const maxDisplayLength = 32 // Maximum characters to display
264-
261+
265262
if len(data) == 0 {
266263
return ""
267264
}
268-
265+
269266
// Convert to string, replacing non-printable characters
270267
var result strings.Builder
271268
for _, b := range data {
@@ -275,14 +272,14 @@ func formatPayloadContent(data []byte) string {
275272
result.WriteString(fmt.Sprintf("\\x%02x", b))
276273
}
277274
}
278-
275+
279276
payloadStr := result.String()
280-
277+
281278
// Truncate if too long
282279
if len(payloadStr) > maxDisplayLength {
283280
payloadStr = payloadStr[:maxDisplayLength-3] + "..."
284281
}
285-
282+
286283
return payloadStr
287284
}
288285

0 commit comments

Comments
 (0)