mirror of
https://tangled.org/evan.jarrett.net/at-container-registry
synced 2026-09-25 11:44:16 +00:00
various linting fixes
This commit is contained in:
@@ -180,7 +180,7 @@ func handleGet() {
|
||||
|
||||
// Wait for user to complete OAuth flow, then retry
|
||||
fmt.Fprintf(os.Stderr, "Waiting for authentication")
|
||||
for i := 0; i < 60; i++ { // Wait up to 2 minutes
|
||||
for range 60 { // Wait up to 2 minutes
|
||||
time.Sleep(2 * time.Second)
|
||||
fmt.Fprintf(os.Stderr, ".")
|
||||
|
||||
@@ -765,7 +765,7 @@ func isNewerVersion(newVersion, currentVersion string) bool {
|
||||
curParts := strings.Split(curV, ".")
|
||||
|
||||
// Compare each part
|
||||
for i := 0; i < len(newParts) && i < len(curParts); i++ {
|
||||
for i := range min(len(newParts), len(curParts)) {
|
||||
newNum := 0
|
||||
curNum := 0
|
||||
fmt.Sscanf(newParts[i], "%d", &newNum)
|
||||
|
||||
@@ -365,14 +365,16 @@ func (s *DeviceStore) RevokeDevice(did, deviceID string) error {
|
||||
}
|
||||
|
||||
// UpdateLastUsed updates the last used timestamp
|
||||
func (s *DeviceStore) UpdateLastUsed(secretHash string) error {
|
||||
func (s *DeviceStore) UpdateLastUsed(secretHash string) {
|
||||
_, err := s.db.Exec(`
|
||||
UPDATE devices
|
||||
SET last_used = ?
|
||||
WHERE secret_hash = ?
|
||||
`, time.Now(), secretHash)
|
||||
|
||||
return err
|
||||
if err != nil {
|
||||
slog.Warn("Failed to update device last used timestamp", "component", "device_store", "error", err)
|
||||
}
|
||||
}
|
||||
|
||||
// CleanupExpired removes expired pending authorizations
|
||||
|
||||
@@ -56,7 +56,7 @@ func TestDevice_Struct(t *testing.T) {
|
||||
func TestGenerateUserCode(t *testing.T) {
|
||||
// Generate multiple codes to test
|
||||
codes := make(map[string]bool)
|
||||
for i := 0; i < 100; i++ {
|
||||
for range 100 {
|
||||
code := generateUserCode()
|
||||
|
||||
// Test format: XXXX-XXXX
|
||||
@@ -372,9 +372,6 @@ func TestDeviceStore_ValidateDeviceSecret(t *testing.T) {
|
||||
return
|
||||
}
|
||||
if !tt.wantErr {
|
||||
if device == nil {
|
||||
t.Error("Expected device, got nil")
|
||||
}
|
||||
if device.DID != "did:plc:alice123" {
|
||||
t.Errorf("DID = %v, want did:plc:alice123", device.DID)
|
||||
}
|
||||
@@ -399,7 +396,7 @@ func TestDeviceStore_ListDevices(t *testing.T) {
|
||||
}
|
||||
|
||||
// Create 3 devices
|
||||
for i := 0; i < 3; i++ {
|
||||
for i := range 3 {
|
||||
pending, err := store.CreatePendingAuth("Device "+string(rune('A'+i)), "192.168.1.1", "Agent")
|
||||
if err != nil {
|
||||
t.Fatalf("CreatePendingAuth() error = %v", err)
|
||||
@@ -417,7 +414,7 @@ func TestDeviceStore_ListDevices(t *testing.T) {
|
||||
}
|
||||
|
||||
// Verify they're sorted by created_at DESC (newest first)
|
||||
for i := 0; i < len(devices)-1; i++ {
|
||||
for i := range len(devices) - 1 {
|
||||
if devices[i].CreatedAt.Before(devices[i+1].CreatedAt) {
|
||||
t.Error("Devices should be sorted by created_at DESC")
|
||||
}
|
||||
@@ -521,10 +518,7 @@ func TestDeviceStore_UpdateLastUsed(t *testing.T) {
|
||||
time.Sleep(10 * time.Millisecond)
|
||||
|
||||
// Update last used
|
||||
err = store.UpdateLastUsed(device.SecretHash)
|
||||
if err != nil {
|
||||
t.Errorf("UpdateLastUsed() error = %v", err)
|
||||
}
|
||||
store.UpdateLastUsed(device.SecretHash)
|
||||
|
||||
// Verify it was updated
|
||||
device2, err := store.ValidateDeviceSecret(secret)
|
||||
|
||||
@@ -213,7 +213,7 @@ func (s *OAuthStore) GetLatestSessionForDID(ctx context.Context, did string) (*o
|
||||
}
|
||||
|
||||
// CleanupOldSessions removes sessions older than the specified duration
|
||||
func (s *OAuthStore) CleanupOldSessions(ctx context.Context, olderThan time.Duration) error {
|
||||
func (s *OAuthStore) CleanupOldSessions(ctx context.Context, olderThan time.Duration) {
|
||||
cutoff := time.Now().Add(-olderThan)
|
||||
|
||||
result, err := s.db.ExecContext(ctx, `
|
||||
@@ -222,19 +222,18 @@ func (s *OAuthStore) CleanupOldSessions(ctx context.Context, olderThan time.Dura
|
||||
`, cutoff)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to cleanup old sessions: %w", err)
|
||||
slog.Warn("Failed to cleanup old OAuth sessions", "component", "oauth_store", "error", err)
|
||||
return
|
||||
}
|
||||
|
||||
deleted, _ := result.RowsAffected()
|
||||
if deleted > 0 {
|
||||
slog.Info("Cleaned up old OAuth sessions", "count", deleted, "older_than", olderThan)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CleanupExpiredAuthRequests removes auth requests older than 10 minutes
|
||||
func (s *OAuthStore) CleanupExpiredAuthRequests(ctx context.Context) error {
|
||||
func (s *OAuthStore) CleanupExpiredAuthRequests(ctx context.Context) {
|
||||
cutoff := time.Now().Add(-10 * time.Minute)
|
||||
|
||||
result, err := s.db.ExecContext(ctx, `
|
||||
@@ -243,15 +242,14 @@ func (s *OAuthStore) CleanupExpiredAuthRequests(ctx context.Context) error {
|
||||
`, cutoff)
|
||||
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to cleanup auth requests: %w", err)
|
||||
slog.Warn("Failed to cleanup expired auth requests", "component", "oauth_store", "error", err)
|
||||
return
|
||||
}
|
||||
|
||||
deleted, _ := result.RowsAffected()
|
||||
if deleted > 0 {
|
||||
slog.Info("Cleaned up expired auth requests", "count", deleted)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// InvalidateSessionsWithMismatchedScopes removes all sessions whose scopes don't match the desired scopes
|
||||
|
||||
@@ -353,9 +353,7 @@ func TestCleanupOldSessions(t *testing.T) {
|
||||
}
|
||||
|
||||
// Run cleanup (remove sessions older than 30 days)
|
||||
if err := store.CleanupOldSessions(ctx, 30*24*time.Hour); err != nil {
|
||||
t.Fatalf("Failed to cleanup old sessions: %v", err)
|
||||
}
|
||||
store.CleanupOldSessions(ctx, 30*24*time.Hour)
|
||||
|
||||
// Verify old session was deleted
|
||||
_, err = store.GetSession(ctx, did1, "old_session")
|
||||
|
||||
@@ -252,7 +252,7 @@ func TestSessionStore_DeleteByDID(t *testing.T) {
|
||||
|
||||
// Create multiple sessions for alice
|
||||
sessionIDs := make([]string, 3)
|
||||
for i := 0; i < 3; i++ {
|
||||
for i := range 3 {
|
||||
id, err := store.Create(did, "alice.bsky.social", "https://pds.example.com", 1*time.Hour)
|
||||
if err != nil {
|
||||
t.Fatalf("Create() error = %v", err)
|
||||
@@ -516,7 +516,7 @@ func TestSessionStore_SessionIDUniqueness(t *testing.T) {
|
||||
|
||||
// Generate multiple session IDs
|
||||
ids := make(map[string]bool)
|
||||
for i := 0; i < 100; i++ {
|
||||
for range 100 {
|
||||
id, err := store.Create("did:plc:alice123", "alice.bsky.social", "https://pds.example.com", 1*time.Hour)
|
||||
if err != nil {
|
||||
t.Fatalf("Create() error = %v", err)
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package holdhealth
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestWorker_Struct(t *testing.T) {
|
||||
// Simple struct test
|
||||
worker := &Worker{}
|
||||
if worker == nil {
|
||||
t.Error("Expected non-nil worker")
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Add background health check tests
|
||||
@@ -675,7 +675,7 @@ func TestProcessAccount(t *testing.T) {
|
||||
}
|
||||
|
||||
// Test 5: Process multiple deactivation events (idempotent)
|
||||
for i := 0; i < 3; i++ {
|
||||
for i := range 3 {
|
||||
err = processor.ProcessAccount(context.Background(), testDID, false, "deactivated")
|
||||
if err != nil {
|
||||
t.Logf("Expected cache invalidation error on iteration %d: %v", i, err)
|
||||
|
||||
@@ -128,8 +128,7 @@ func (w *Worker) Start(ctx context.Context) error {
|
||||
|
||||
// Reset read deadline - we know connection is alive
|
||||
// Allow 90 seconds for next pong (3x ping interval)
|
||||
conn.SetReadDeadline(time.Now().Add(90 * time.Second))
|
||||
return nil
|
||||
return conn.SetReadDeadline(time.Now().Add(90 * time.Second))
|
||||
})
|
||||
|
||||
// Set initial read deadline
|
||||
|
||||
@@ -318,7 +318,7 @@ func TestMiddleware_ConcurrentAccess(t *testing.T) {
|
||||
// Pre-create all users and sessions before concurrent access
|
||||
// This ensures database is fully initialized before goroutines start
|
||||
sessionIDs := make([]string, 10)
|
||||
for i := 0; i < 10; i++ {
|
||||
for i := range 10 {
|
||||
did := fmt.Sprintf("did:plc:user%d", i)
|
||||
handle := fmt.Sprintf("user%d.bsky.social", i)
|
||||
|
||||
@@ -358,7 +358,7 @@ func TestMiddleware_ConcurrentAccess(t *testing.T) {
|
||||
var wg sync.WaitGroup
|
||||
var mu sync.Mutex // Protect results map
|
||||
|
||||
for i := 0; i < 10; i++ {
|
||||
for i := range 10 {
|
||||
wg.Add(1)
|
||||
go func(index int, sessionID string) {
|
||||
defer wg.Done()
|
||||
|
||||
@@ -555,7 +555,7 @@ func ExtractAuthMethod(next http.Handler) http.Handler {
|
||||
|
||||
// Store HTTP method in context for routing decisions
|
||||
// This is used by routing_repository.go to distinguish pull (GET/HEAD) from push (PUT/POST)
|
||||
ctx = context.WithValue(ctx, "http.request.method", r.Method)
|
||||
ctx = context.WithValue(ctx, storage.HTTPRequestMethod, r.Method)
|
||||
|
||||
// Extract Authorization header
|
||||
authHeader := r.Header.Get("Authorization")
|
||||
|
||||
+14
-13
@@ -143,9 +143,10 @@ func (c *Card) DrawText(text string, x, y float64, size float64, col color.Color
|
||||
defer face.Close()
|
||||
|
||||
textWidth := font.MeasureString(face, text).Round()
|
||||
if align == AlignCenter {
|
||||
switch align {
|
||||
case AlignCenter:
|
||||
x -= float64(textWidth) / 2
|
||||
} else if align == AlignRight {
|
||||
case AlignRight:
|
||||
x -= float64(textWidth)
|
||||
}
|
||||
}
|
||||
@@ -292,21 +293,21 @@ func (c *Card) DrawPlaceholderCircle(x, y, diameter int, bgColor, textColor colo
|
||||
// DrawRoundedRect draws a filled rounded rectangle
|
||||
func (c *Card) DrawRoundedRect(x, y, w, h, radius int, col color.Color) {
|
||||
// Draw main rectangle (without corners)
|
||||
for dy := radius; dy < h-radius; dy++ {
|
||||
for dx := 0; dx < w; dx++ {
|
||||
c.img.Set(x+dx, y+dy, col)
|
||||
for dy := range h - 2*radius {
|
||||
for dx := range w {
|
||||
c.img.Set(x+dx, y+radius+dy, col)
|
||||
}
|
||||
}
|
||||
// Draw top and bottom strips (without corners)
|
||||
for dy := 0; dy < radius; dy++ {
|
||||
for dx := radius; dx < w-radius; dx++ {
|
||||
c.img.Set(x+dx, y+dy, col)
|
||||
c.img.Set(x+dx, y+h-1-dy, col)
|
||||
for dy := range radius {
|
||||
for dx := range w - 2*radius {
|
||||
c.img.Set(x+radius+dx, y+dy, col)
|
||||
c.img.Set(x+radius+dx, y+h-1-dy, col)
|
||||
}
|
||||
}
|
||||
// Draw rounded corners
|
||||
for dy := 0; dy < radius; dy++ {
|
||||
for dx := 0; dx < radius; dx++ {
|
||||
for dy := range radius {
|
||||
for dx := range radius {
|
||||
// Check if point is within circle
|
||||
cx := radius - dx - 1
|
||||
cy := radius - dy - 1
|
||||
@@ -388,8 +389,8 @@ func createCircleMask(diameter int) *image.Alpha {
|
||||
centerX := radius
|
||||
centerY := radius
|
||||
|
||||
for y := 0; y < diameter; y++ {
|
||||
for x := 0; x < diameter; x++ {
|
||||
for y := range diameter {
|
||||
for x := range diameter {
|
||||
dx := x - centerX
|
||||
dy := y - centerY
|
||||
if dx*dx+dy*dy <= radius*radius {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// Package readme provides fetching and rendering of README files from Git hosting platforms.
|
||||
package readme
|
||||
|
||||
import (
|
||||
|
||||
@@ -301,7 +301,7 @@ func containsSubstring(s, substr string) bool {
|
||||
}
|
||||
|
||||
func containsSubstringHelper(s, substr string) bool {
|
||||
for i := 0; i <= len(s)-len(substr); i++ {
|
||||
for i := range len(s) - len(substr) + 1 {
|
||||
if s[i:i+len(substr)] == substr {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ func (s *ManifestStore) Get(ctx context.Context, dgst digest.Digest, options ...
|
||||
// Notify hold about manifest pull (for stats tracking)
|
||||
// Only count GET requests (actual downloads), not HEAD requests (existence checks)
|
||||
// Check HTTP method from context (distribution library stores it as "http.request.method")
|
||||
if method, ok := ctx.Value("http.request.method").(string); ok && method == "GET" {
|
||||
if method, ok := ctx.Value(HTTPRequestMethod).(string); ok && method == "GET" {
|
||||
// Do this asynchronously to avoid blocking the response
|
||||
if s.ctx.ServiceToken != "" && s.ctx.Handle != "" {
|
||||
go func() {
|
||||
|
||||
@@ -340,7 +340,7 @@ func TestGetProfile_MigrationLocking(t *testing.T) {
|
||||
|
||||
// Make 5 concurrent GetProfile calls
|
||||
var wg sync.WaitGroup
|
||||
for i := 0; i < 5; i++ {
|
||||
for range 5 {
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
@@ -552,7 +552,7 @@ func (p *ProxyBlobStore) completeMultipartUpload(ctx context.Context, digest, up
|
||||
}
|
||||
|
||||
// abortMultipartUpload aborts a multipart upload via XRPC abortUpload endpoint
|
||||
func (p *ProxyBlobStore) abortMultipartUpload(ctx context.Context, digest, uploadID string) error {
|
||||
func (p *ProxyBlobStore) abortMultipartUpload(ctx context.Context, uploadID string) error {
|
||||
reqBody := map[string]any{
|
||||
"uploadId": uploadID,
|
||||
}
|
||||
@@ -760,8 +760,10 @@ func (w *ProxyBlobWriter) Commit(ctx context.Context, desc distribution.Descript
|
||||
slog.Debug("Flushing final buffer", "component", "proxy_blob_store/Commit", "bytes", w.buffer.Len())
|
||||
if err := w.flushPart(); err != nil {
|
||||
// Try to abort multipart on error
|
||||
tempDigest := fmt.Sprintf("uploads/temp-%s", w.id)
|
||||
w.store.abortMultipartUpload(ctx, tempDigest, w.uploadID)
|
||||
if err := w.store.abortMultipartUpload(ctx, w.uploadID); err != nil {
|
||||
slog.Warn("Failed to abort multipart upload", "component", "proxy_blob_store/Cancel", "error", err)
|
||||
// Continue anyway - we want to mark upload as cancelled
|
||||
}
|
||||
return distribution.Descriptor{}, fmt.Errorf("failed to flush final part: %w", err)
|
||||
}
|
||||
}
|
||||
@@ -794,8 +796,7 @@ func (w *ProxyBlobWriter) Cancel(ctx context.Context) error {
|
||||
globalUploadsMu.Unlock()
|
||||
|
||||
// Abort multipart upload
|
||||
tempDigest := fmt.Sprintf("uploads/temp-%s", w.id)
|
||||
if err := w.store.abortMultipartUpload(ctx, tempDigest, w.uploadID); err != nil {
|
||||
if err := w.store.abortMultipartUpload(ctx, w.uploadID); err != nil {
|
||||
slog.Warn("Failed to abort multipart upload", "component", "proxy_blob_store/Cancel", "error", err)
|
||||
// Continue anyway - we want to mark upload as cancelled
|
||||
}
|
||||
|
||||
@@ -563,7 +563,7 @@ func TestMultipartEndpoints_CorrectURLs(t *testing.T) {
|
||||
{
|
||||
name: "abortMultipartUpload",
|
||||
testFunc: func(store *ProxyBlobStore) error {
|
||||
return store.abortMultipartUpload(context.Background(), "sha256:test", "upload-123")
|
||||
return store.abortMultipartUpload(context.Background(), "upload-123")
|
||||
},
|
||||
expectedPath: atproto.HoldAbortUpload,
|
||||
},
|
||||
|
||||
@@ -11,6 +11,10 @@ import (
|
||||
"github.com/distribution/distribution/v3"
|
||||
)
|
||||
|
||||
type contextKey string
|
||||
|
||||
const HTTPRequestMethod contextKey = "http.request.method"
|
||||
|
||||
// RoutingRepository routes manifests to ATProto and blobs to external hold service
|
||||
// The registry (AppView) is stateless and NEVER stores blobs locally
|
||||
// NOTE: A fresh instance is created per-request (see middleware/registry.go)
|
||||
@@ -55,7 +59,7 @@ func (r *RoutingRepository) Blobs(ctx context.Context) distribution.BlobStore {
|
||||
// Push operations use the discovery-based hold DID from user's profile/default
|
||||
// This allows users to change their default hold and have new pushes go there
|
||||
isPull := false
|
||||
if method, ok := ctx.Value("http.request.method").(string); ok {
|
||||
if method, ok := ctx.Value(HTTPRequestMethod).(string); ok {
|
||||
isPull = method == "GET" || method == "HEAD"
|
||||
}
|
||||
|
||||
|
||||
@@ -126,7 +126,7 @@ func TestRoutingRepository_Blobs_PullUsesDatabase(t *testing.T) {
|
||||
}
|
||||
repo := NewRoutingRepository(nil, ctx)
|
||||
|
||||
pullCtx := context.WithValue(context.Background(), "http.request.method", method)
|
||||
pullCtx := context.WithValue(context.Background(), HTTPRequestMethod, method)
|
||||
blobStore := repo.Blobs(pullCtx)
|
||||
|
||||
assert.NotNil(t, blobStore)
|
||||
@@ -164,7 +164,7 @@ func TestRoutingRepository_Blobs_PushUsesDiscovery(t *testing.T) {
|
||||
repo := NewRoutingRepository(nil, ctx)
|
||||
|
||||
// Create context with push method
|
||||
pushCtx := context.WithValue(context.Background(), "http.request.method", tc.method)
|
||||
pushCtx := context.WithValue(context.Background(), HTTPRequestMethod, tc.method)
|
||||
blobStore := repo.Blobs(pushCtx)
|
||||
|
||||
assert.NotNil(t, blobStore)
|
||||
@@ -330,7 +330,7 @@ func TestRoutingRepository_ConcurrentAccess(t *testing.T) {
|
||||
wg.Wait()
|
||||
|
||||
// Verify all stores are non-nil (due to race conditions, they may not all be the same instance)
|
||||
for i := 0; i < numGoroutines; i++ {
|
||||
for i := range numGoroutines {
|
||||
assert.NotNil(t, manifestStores[i], "manifest store should not be nil")
|
||||
}
|
||||
|
||||
@@ -351,7 +351,7 @@ func TestRoutingRepository_ConcurrentAccess(t *testing.T) {
|
||||
wg.Wait()
|
||||
|
||||
// Verify all stores are non-nil (due to race conditions, they may not all be the same instance)
|
||||
for i := 0; i < numGoroutines; i++ {
|
||||
for i := range numGoroutines {
|
||||
assert.NotNil(t, blobStores[i], "blob store should not be nil")
|
||||
}
|
||||
|
||||
@@ -376,7 +376,7 @@ func TestRoutingRepository_Blobs_PullPriority(t *testing.T) {
|
||||
repo := NewRoutingRepository(nil, ctx)
|
||||
|
||||
// For pull (GET), database should take priority
|
||||
pullCtx := context.WithValue(context.Background(), "http.request.method", "GET")
|
||||
pullCtx := context.WithValue(context.Background(), HTTPRequestMethod, "GET")
|
||||
blobStore := repo.Blobs(pullCtx)
|
||||
|
||||
assert.NotNil(t, blobStore)
|
||||
|
||||
@@ -35,7 +35,7 @@ func TestGetDirectoryConcurrency(t *testing.T) {
|
||||
instances := make(chan any, numGoroutines)
|
||||
|
||||
// Launch many goroutines concurrently accessing GetDirectory
|
||||
for i := 0; i < numGoroutines; i++ {
|
||||
for range numGoroutines {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
dir := GetDirectory()
|
||||
@@ -73,7 +73,7 @@ func TestGetDirectorySequential(t *testing.T) {
|
||||
t.Run("multiple calls in sequence", func(t *testing.T) {
|
||||
// Get directory multiple times in sequence
|
||||
dirs := make([]any, 10)
|
||||
for i := 0; i < 10; i++ {
|
||||
for i := range 10 {
|
||||
dirs[i] = GetDirectory()
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
// Package token provides service token caching and management for AppView.
|
||||
// Package auth provides service token caching and management for AppView.
|
||||
// Service tokens are JWTs issued by a user's PDS to authorize AppView to
|
||||
// act on their behalf when communicating with hold services. Tokens are
|
||||
// cached with automatic expiry parsing and 10-second safety margins.
|
||||
|
||||
@@ -14,17 +14,6 @@ import (
|
||||
"atcr.io/pkg/atproto"
|
||||
)
|
||||
|
||||
func TestNewRemoteHoldAuthorizer(t *testing.T) {
|
||||
// Test with nil database (should still work)
|
||||
authorizer := NewRemoteHoldAuthorizer(nil, false)
|
||||
if authorizer == nil {
|
||||
t.Fatal("Expected non-nil authorizer")
|
||||
}
|
||||
|
||||
// Verify it implements the HoldAuthorizer interface
|
||||
var _ HoldAuthorizer = authorizer
|
||||
}
|
||||
|
||||
func TestNewRemoteHoldAuthorizer_TestMode(t *testing.T) {
|
||||
// Test with testMode enabled
|
||||
authorizer := NewRemoteHoldAuthorizer(nil, true)
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package oauth
|
||||
|
||||
import (
|
||||
"github.com/bluesky-social/indigo/atproto/auth/oauth"
|
||||
"testing"
|
||||
|
||||
"github.com/bluesky-social/indigo/atproto/auth/oauth"
|
||||
)
|
||||
|
||||
func TestNewClientApp(t *testing.T) {
|
||||
|
||||
@@ -2,12 +2,13 @@ package oauth
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/bluesky-social/indigo/atproto/auth/oauth"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/bluesky-social/indigo/atproto/auth/oauth"
|
||||
)
|
||||
|
||||
func TestNewServer(t *testing.T) {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// Package token provides JWT claims and token handling for registry authentication.
|
||||
package token
|
||||
|
||||
import (
|
||||
|
||||
@@ -150,7 +150,7 @@ func TestAddToHistory_RingBuffer(t *testing.T) {
|
||||
testCID, _ := cid.Decode("bafyreib2rxk3rkhh5ylyxj3x3gathxt3s32qvwj2lf3qg4kmzr6b7teqke")
|
||||
|
||||
// Broadcast 5 events (exceeds maxHistory of 3)
|
||||
for i := 0; i < 5; i++ {
|
||||
for range 5 {
|
||||
event := &RepoEvent{
|
||||
NewRoot: testCID,
|
||||
Rev: "test-rev",
|
||||
|
||||
@@ -377,7 +377,7 @@ defaults:
|
||||
}
|
||||
|
||||
// Create layer records for owner
|
||||
for i := 0; i < 3; i++ {
|
||||
for i := range 3 {
|
||||
record := atproto.NewLayerRecord(
|
||||
"sha256:owner"+string(rune('a'+i)),
|
||||
1024*1024*100, // 100MB each
|
||||
@@ -454,7 +454,7 @@ defaults:
|
||||
addCrewMemberWithBerth(t, pds, crewDID, "writer", []string{"blob:write"}, "")
|
||||
|
||||
// Create layer records for crew member
|
||||
for i := 0; i < 2; i++ {
|
||||
for i := range 2 {
|
||||
record := atproto.NewLayerRecord(
|
||||
"sha256:crew"+string(rune('a'+i)),
|
||||
1024*1024*50, // 50MB each
|
||||
@@ -685,7 +685,7 @@ defaults:
|
||||
|
||||
// Create multiple layer records with same digest (should be deduplicated)
|
||||
digest := "sha256:duplicatelayer"
|
||||
for i := 0; i < 5; i++ {
|
||||
for i := range 5 {
|
||||
record := atproto.NewLayerRecord(
|
||||
digest,
|
||||
1024*1024*100, // 100MB
|
||||
|
||||
@@ -322,7 +322,7 @@ func TestRecordsIndex_ListRecords_Limit(t *testing.T) {
|
||||
defer ri.Close()
|
||||
|
||||
// Add 5 records
|
||||
for i := 0; i < 5; i++ {
|
||||
for i := range 5 {
|
||||
rkey := string(rune('a' + i))
|
||||
if err := ri.IndexRecord("io.atcr.hold.crew", rkey, "cid-"+rkey); err != nil {
|
||||
t.Fatalf("IndexRecord() error = %v", err)
|
||||
@@ -473,10 +473,10 @@ func TestRecordsIndex_Count(t *testing.T) {
|
||||
defer ri.Close()
|
||||
|
||||
// Add records to two collections
|
||||
for i := 0; i < 3; i++ {
|
||||
for i := range 3 {
|
||||
ri.IndexRecord("io.atcr.hold.crew", string(rune('a'+i)), "cid1")
|
||||
}
|
||||
for i := 0; i < 5; i++ {
|
||||
for i := range 5 {
|
||||
ri.IndexRecord("io.atcr.hold.captain", string(rune('a'+i)), "cid2")
|
||||
}
|
||||
|
||||
|
||||
@@ -103,8 +103,7 @@ func NewHoldPDS(ctx context.Context, did, publicURL, dbPath, keyPath string, ena
|
||||
// Uses same database as carstore for simplicity
|
||||
var recordsIndex *RecordsIndex
|
||||
if dbPath != ":memory:" {
|
||||
recordsDbPath := dbPath + "/db.sqlite3"
|
||||
recordsIndex, err = NewRecordsIndex(recordsDbPath)
|
||||
recordsIndex, err = NewRecordsIndex(dbPath + "/db.sqlite3")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to create records index: %w", err)
|
||||
}
|
||||
|
||||
@@ -232,7 +232,7 @@ func contains(s, substr string) bool {
|
||||
}
|
||||
|
||||
func findSubstring(s, substr string) bool {
|
||||
for i := 0; i <= len(s)-len(substr); i++ {
|
||||
for i := range len(s) - len(substr) + 1 {
|
||||
if s[i:i+len(substr)] == substr {
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -609,7 +609,7 @@ func TestHandleListRecords_Pagination(t *testing.T) {
|
||||
|
||||
// Note: Bootstrap already added 1 crew member
|
||||
// Add 4 more for a total of 5
|
||||
for i := 0; i < 4; i++ {
|
||||
for i := range 4 {
|
||||
_, err := handler.pds.AddCrewMember(ctx, "did:plc:member"+string(rune(i+'0')), "reader", []string{"blob:read"})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to add crew member: %v", err)
|
||||
@@ -673,7 +673,7 @@ func TestHandleListRecords_Reverse(t *testing.T) {
|
||||
holdDID := "did:web:hold.example.com"
|
||||
|
||||
// Add crew members
|
||||
for i := 0; i < 3; i++ {
|
||||
for i := range 3 {
|
||||
_, err := handler.pds.AddCrewMember(ctx, "did:plc:member"+string(rune(i+'0')), "reader", []string{"blob:read"})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to add crew member: %v", err)
|
||||
@@ -888,7 +888,7 @@ func TestHandleListRecords_Indexed_Pagination(t *testing.T) {
|
||||
holdDID := "did:web:hold.example.com"
|
||||
|
||||
// Add 4 more crew members for total of 5
|
||||
for i := 0; i < 4; i++ {
|
||||
for i := range 4 {
|
||||
_, err := handler.pds.AddCrewMember(ctx, fmt.Sprintf("did:plc:member%d", i), "reader", []string{"blob:read"})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to add crew member: %v", err)
|
||||
@@ -968,7 +968,7 @@ func TestHandleListRecords_Indexed_Reverse(t *testing.T) {
|
||||
holdDID := "did:web:hold.example.com"
|
||||
|
||||
// Add crew members
|
||||
for i := 0; i < 3; i++ {
|
||||
for i := range 3 {
|
||||
_, err := handler.pds.AddCrewMember(ctx, fmt.Sprintf("did:plc:member%d", i), "reader", []string{"blob:read"})
|
||||
if err != nil {
|
||||
t.Fatalf("Failed to add crew member: %v", err)
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
// Package quota provides storage quota management for hold services.
|
||||
package quota
|
||||
|
||||
import (
|
||||
|
||||
@@ -366,7 +366,7 @@ func BenchmarkInitLogger(b *testing.B) {
|
||||
defer slog.SetDefault(originalLogger)
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for range b.N {
|
||||
InitLogger("info")
|
||||
}
|
||||
}
|
||||
@@ -376,7 +376,7 @@ func BenchmarkSetupTestLogger(b *testing.B) {
|
||||
defer slog.SetDefault(originalLogger)
|
||||
|
||||
b.ResetTimer()
|
||||
for i := 0; i < b.N; i++ {
|
||||
for range b.N {
|
||||
cleanup := SetupTestLogger()
|
||||
cleanup()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user