Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
repos:
- repo: https://github.com/golangci/golangci-lint
rev: v1.64.8
hooks:
- id: golangci-lint

- repo: local
hooks:
- id: go-test
name: go test
entry: go test ./... -race -count=1
language: system
pass_filenames: false
types: [go]
4 changes: 3 additions & 1 deletion cmd/probe/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ func main() {
if healthSrv != nil {
shutdownCtx, shutdownCancel := context.WithTimeout(context.Background(), 5*1e9) // 5s
defer shutdownCancel()
healthSrv.Shutdown(shutdownCtx)
if err := healthSrv.Shutdown(shutdownCtx); err != nil {
logger.Error("health server shutdown error", "error", err)
}
}

logger.Info("krakenkey-probe stopped")
Expand Down
44 changes: 33 additions & 11 deletions internal/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,9 @@ endpoints:
- host: "example.com"
port: 443
`
os.WriteFile(cfgPath, []byte(yaml), 0o644)
if err := os.WriteFile(cfgPath, []byte(yaml), 0o644); err != nil {
t.Fatal(err)
}

_, err := Load(cfgPath)
if err == nil {
Expand All @@ -183,7 +185,9 @@ endpoints:
- host: "example.com"
port: 443
`
os.WriteFile(cfgPath, []byte(yaml), 0o644)
if err := os.WriteFile(cfgPath, []byte(yaml), 0o644); err != nil {
t.Fatal(err)
}

_, err := Load(cfgPath)
if err == nil {
Expand All @@ -200,7 +204,9 @@ api:
key: "kk_testkey"
endpoints: []
`
os.WriteFile(cfgPath, []byte(yaml), 0o644)
if err := os.WriteFile(cfgPath, []byte(yaml), 0o644); err != nil {
t.Fatal(err)
}

_, err := Load(cfgPath)
if err == nil {
Expand All @@ -221,7 +227,9 @@ endpoints:
- host: "example.com"
port: 443
`
os.WriteFile(cfgPath, []byte(yaml), 0o644)
if err := os.WriteFile(cfgPath, []byte(yaml), 0o644); err != nil {
t.Fatal(err)
}

_, err := Load(cfgPath)
if err == nil {
Expand All @@ -242,7 +250,9 @@ endpoints:
- host: "example.com"
port: 443
`
os.WriteFile(cfgPath, []byte(yaml), 0o644)
if err := os.WriteFile(cfgPath, []byte(yaml), 0o644); err != nil {
t.Fatal(err)
}

_, err := Load(cfgPath)
if err == nil {
Expand All @@ -261,7 +271,9 @@ endpoints:
- host: "example.com"
port: 0
`
os.WriteFile(cfgPath, []byte(yaml), 0o644)
if err := os.WriteFile(cfgPath, []byte(yaml), 0o644); err != nil {
t.Fatal(err)
}

_, err := Load(cfgPath)
if err == nil {
Expand All @@ -282,7 +294,9 @@ endpoints:
- host: "example.com"
port: 443
`
os.WriteFile(cfgPath, []byte(yaml), 0o644)
if err := os.WriteFile(cfgPath, []byte(yaml), 0o644); err != nil {
t.Fatal(err)
}

_, err := Load(cfgPath)
if err == nil {
Expand All @@ -301,7 +315,9 @@ probe:
mode: "hosted"
id: "some-uuid"
`
os.WriteFile(cfgPath, []byte(yaml), 0o644)
if err := os.WriteFile(cfgPath, []byte(yaml), 0o644); err != nil {
t.Fatal(err)
}

_, err := Load(cfgPath)
if err == nil {
Expand All @@ -320,7 +336,9 @@ probe:
mode: "hosted"
region: "us-east-1"
`
os.WriteFile(cfgPath, []byte(yaml), 0o644)
if err := os.WriteFile(cfgPath, []byte(yaml), 0o644); err != nil {
t.Fatal(err)
}

_, err := Load(cfgPath)
if err == nil {
Expand All @@ -340,7 +358,9 @@ probe:
id: "some-uuid"
region: "us-east-1"
`
os.WriteFile(cfgPath, []byte(yaml), 0o644)
if err := os.WriteFile(cfgPath, []byte(yaml), 0o644); err != nil {
t.Fatal(err)
}

cfg, err := Load(cfgPath)
if err != nil {
Expand All @@ -367,7 +387,9 @@ logging:
level: "trace"
format: "json"
`
os.WriteFile(cfgPath, []byte(yaml), 0o644)
if err := os.WriteFile(cfgPath, []byte(yaml), 0o644); err != nil {
t.Fatal(err)
}

_, err := Load(cfgPath)
if err == nil {
Expand Down
6 changes: 3 additions & 3 deletions internal/health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func (s *Server) handleHealthz(w http.ResponseWriter, r *http.Request) {

w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(status)
_ = json.NewEncoder(w).Encode(status)
}

func (s *Server) handleReadyz(w http.ResponseWriter, r *http.Request) {
Expand All @@ -99,10 +99,10 @@ func (s *Server) handleReadyz(w http.ResponseWriter, r *http.Request) {

if !ready {
w.WriteHeader(http.StatusServiceUnavailable)
json.NewEncoder(w).Encode(map[string]string{"status": "not ready"})
_ = json.NewEncoder(w).Encode(map[string]string{"status": "not ready"})
return
}

w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]string{"status": "ready"})
_ = json.NewEncoder(w).Encode(map[string]string{"status": "ready"})
}
12 changes: 9 additions & 3 deletions internal/health/health_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ func TestHealthzWithScanTimes(t *testing.T) {
s.handleHealthz(rec, req)

var status Status
json.NewDecoder(rec.Body).Decode(&status)
if err := json.NewDecoder(rec.Body).Decode(&status); err != nil {
t.Fatalf("decode error: %v", err)
}

if status.LastScan != "2026-03-15T12:00:00Z" {
t.Errorf("lastScan = %q, want %q", status.LastScan, "2026-03-15T12:00:00Z")
Expand All @@ -79,7 +81,9 @@ func TestReadyzNotReady(t *testing.T) {
}

var body map[string]string
json.NewDecoder(rec.Body).Decode(&body)
if err := json.NewDecoder(rec.Body).Decode(&body); err != nil {
t.Fatalf("decode error: %v", err)
}
if body["status"] != "not ready" {
t.Errorf("status = %q, want %q", body["status"], "not ready")
}
Expand All @@ -99,7 +103,9 @@ func TestReadyzAfterReady(t *testing.T) {
}

var body map[string]string
json.NewDecoder(rec.Body).Decode(&body)
if err := json.NewDecoder(rec.Body).Decode(&body); err != nil {
t.Fatalf("decode error: %v", err)
}
if body["status"] != "ready" {
t.Errorf("status = %q, want %q", body["status"], "ready")
}
Expand Down
10 changes: 5 additions & 5 deletions internal/reporter/reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func TestRegisterSuccess(t *testing.T) {
t.Error("User-Agent is empty")
}

json.NewDecoder(r.Body).Decode(&received)
_ = json.NewDecoder(r.Body).Decode(&received)
w.WriteHeader(http.StatusOK)
}))
defer srv.Close()
Expand Down Expand Up @@ -69,7 +69,7 @@ func TestReportSuccess(t *testing.T) {
if r.URL.Path != "/probes/report" {
t.Errorf("path = %s, want /probes/report", r.URL.Path)
}
json.NewDecoder(r.Body).Decode(&received)
_ = json.NewDecoder(r.Body).Decode(&received)
w.WriteHeader(http.StatusOK)
}))
defer srv.Close()
Expand Down Expand Up @@ -116,7 +116,7 @@ func TestReportSuccess(t *testing.T) {
func TestReport401(t *testing.T) {
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusUnauthorized)
w.Write([]byte(`{"error":"invalid key"}`))
_, _ = w.Write([]byte(`{"error":"invalid key"}`))
}))
defer srv.Close()

Expand Down Expand Up @@ -205,7 +205,7 @@ func TestFetchHostedConfig(t *testing.T) {
},
Interval: "5m",
}
json.NewEncoder(w).Encode(cfg)
_ = json.NewEncoder(w).Encode(cfg)
}))
defer srv.Close()

Expand Down Expand Up @@ -242,5 +242,5 @@ func TestUserAgent(t *testing.T) {
defer srv.Close()

rep := New(srv.URL, "kk_testkey", "1.2.3", "linux", "amd64")
rep.Register(context.Background(), ProbeInfo{})
_ = rep.Register(context.Background(), ProbeInfo{})
}
4 changes: 2 additions & 2 deletions internal/scanner/scanner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ func newTestTLSServer(t *testing.T, opts ...func(*x509.Certificate)) (net.Listen
go func(c net.Conn) {
defer c.Close()
tlsConn := c.(*tls.Conn)
tlsConn.Handshake()
_ = tlsConn.Handshake()
}(conn)
}
}()
Expand Down Expand Up @@ -227,7 +227,7 @@ func TestScanEndpointTimeout(t *testing.T) {
// Hold connection open, never respond
go func(c net.Conn) {
buf := make([]byte, 1024)
c.Read(buf) // block until closed
_, _ = c.Read(buf) // block until closed
c.Close()
}(conn)
}
Expand Down
8 changes: 4 additions & 4 deletions internal/scheduler/scheduler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func TestRunCycleSelfHosted(t *testing.T) {
}
if r.URL.Path == "/probes/report" {
var report reporter.ScanReport
json.NewDecoder(r.Body).Decode(&report)
_ = json.NewDecoder(r.Body).Decode(&report)
if len(report.Results) > 0 {
reportReceived.Store(true)
}
Expand Down Expand Up @@ -87,7 +87,7 @@ func TestRunCycleHostedMode(t *testing.T) {
},
"interval": "5m",
}
json.NewEncoder(w).Encode(cfg)
_ = json.NewEncoder(w).Encode(cfg)
return
}
if r.URL.Path == "/probes/report" {
Expand Down Expand Up @@ -205,11 +205,11 @@ func TestRunSetsReady(t *testing.T) {
mux := http.NewServeMux()
mux.HandleFunc("/readyz", func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusOK)
json.NewEncoder(w).Encode(map[string]string{"status": "ready"})
_ = json.NewEncoder(w).Encode(map[string]string{"status": "ready"})
})
mux.ServeHTTP(rec, req)

json.NewDecoder(rec.Body).Decode(&body)
_ = json.NewDecoder(rec.Body).Decode(&body)
if body["status"] != "ready" {
t.Errorf("expected ready status, got %q", body["status"])
}
Expand Down
4 changes: 3 additions & 1 deletion internal/state/state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ func TestLoadOrCreateReusesExistingID(t *testing.T) {
RegisteredAt: "2026-01-01T00:00:00Z",
}
data, _ := json.Marshal(existing)
os.WriteFile(stateFile, data, 0o644)
if err := os.WriteFile(stateFile, data, 0o644); err != nil {
t.Fatal(err)
}

cfg := &config.Config{
Probe: config.ProbeConfig{
Expand Down
Loading