Watch
1
0
Fork
You've already forked pkg-proxy
1
mirror of https://github.com/git-pkgs/proxy.git synced 2026-08-23 20:34:56 -04:00
pkg-proxy/internal/enrichment/enrichment_test.go
Andrew Nesbitt 272e6d9040
Lint and dead-code cleanup (#279)
* Bump go tool golangci-lint to v2.13.1

The .golangci.yml goconst.ignore-tests setting was added in v2.12.0
(golangci/golangci-lint#6480). On the previously pinned v2.10.1,
config verify fails with "additional properties 'ignore-tests' not
allowed" and the setting is silently ignored at run time, so goconst
counts test-file literals toward min-occurrences.

* Apply gofmt and CutSuffix simplification

- gofmt -w internal/server/health_test.go
- Replace HasSuffix+TrimSuffix with CutSuffix in ParseSize

* Remove dead code and migrate tests off legacy Filesystem storage

Migrate the three test call sites of storage.NewFilesystem to
storage.OpenBucket("file://...") and drop the deprecated
StorageConfig.Path field from test configs, then delete code that
deadcode reports as unreachable from cmd/proxy:

- internal/storage/filesystem.go and its tests
- storage.HashingReader
- enrichment.Service.BulkCheckVulnerabilities and NormalizeLicense
- server.ActiveRequestsMiddleware (no-op body; the real tracking
  is the inline r.Use at server.go:226)
- mirror.RegistrySource (unimplemented stub)

metrics.UpdateCircuitBreakerState and RecordCircuitBreakerTrip are
kept because #275 wires them.

Update the CONTRIBUTING.md storage section to reflect blob.go.
2026-08-21 09:26:27 +01:00

76 lines
1.6 KiB
Go

package enrichment
import (
"log/slog"
"os"
"testing"
)
func TestNew(t *testing.T) {
logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
svc := New(logger)
if svc == nil {
t.Fatal("New() returned nil")
}
if svc.regClient == nil {
t.Error("regClient is nil")
}
if svc.vulnSource == nil {
t.Error("vulnSource is nil")
}
}
func TestIsOutdated(t *testing.T) {
logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
svc := New(logger)
tests := []struct {
current string
latest string
expected bool
}{
{"1.0.0", "2.0.0", true},
{"2.0.0", "2.0.0", false},
{"2.0.0", "1.0.0", false},
{"1.0.0", "", false},
{"", "2.0.0", false},
{"1.2.3", "1.2.4", true},
{"1.2.4", "1.2.3", false},
}
for _, tc := range tests {
result := svc.IsOutdated(tc.current, tc.latest)
if result != tc.expected {
t.Errorf("IsOutdated(%q, %q) = %v, want %v", tc.current, tc.latest, result, tc.expected)
}
}
}
func TestCategorizeLicense(t *testing.T) {
logger := slog.New(slog.NewTextHandler(os.Stdout, nil))
svc := New(logger)
tests := []struct {
license string
expected LicenseCategory
}{
{"MIT", LicensePermissive},
{"Apache-2.0", LicensePermissive},
{"BSD-3-Clause", LicensePermissive},
{"GPL-3.0", LicenseCopyleft},
{"AGPL-3.0", LicenseCopyleft},
{"LGPL-2.1", LicenseCopyleft},
{"", LicenseUnknown},
{"Unknown", LicenseUnknown},
}
for _, tc := range tests {
result := svc.CategorizeLicense(tc.license)
if result != tc.expected {
t.Errorf("CategorizeLicense(%q) = %v, want %v", tc.license, result, tc.expected)
}
}
}