A container registry that uses the AT Protocol for manifest storage and S3 for blob storage.
1package storage
2
3import (
4 "testing"
5
6 "atcr.io/pkg/atproto"
7)
8
9// Mock implementations for testing
10
11// mockHoldDIDLookup implements HoldDIDLookup for testing
12type mockHoldDIDLookup struct {
13 holdDID string // Return value for GetLatestHoldDIDForRepo
14}
15
16func (m *mockHoldDIDLookup) GetLatestHoldDIDForRepo(did, repository string) (string, error) {
17 return m.holdDID, nil
18}
19
20type mockHoldAuthorizer struct{}
21
22func (m *mockHoldAuthorizer) Authorize(holdDID, userDID, permission string) (bool, error) {
23 return true, nil
24}
25
26func TestRegistryContext_Fields(t *testing.T) {
27 // Create a sample RegistryContext
28 ctx := &RegistryContext{
29 DID: "did:plc:test123",
30 Handle: "alice.bsky.social",
31 HoldDID: "did:web:hold01.atcr.io",
32 PDSEndpoint: "https://bsky.social",
33 Repository: "debian",
34 ServiceToken: "test-token",
35 ATProtoClient: &atproto.Client{
36 // Mock client - would need proper initialization in real tests
37 },
38 Database: &mockHoldDIDLookup{holdDID: "did:web:hold01.atcr.io"},
39 }
40
41 // Verify fields are accessible
42 if ctx.DID != "did:plc:test123" {
43 t.Errorf("Expected DID %q, got %q", "did:plc:test123", ctx.DID)
44 }
45 if ctx.Handle != "alice.bsky.social" {
46 t.Errorf("Expected Handle %q, got %q", "alice.bsky.social", ctx.Handle)
47 }
48 if ctx.HoldDID != "did:web:hold01.atcr.io" {
49 t.Errorf("Expected HoldDID %q, got %q", "did:web:hold01.atcr.io", ctx.HoldDID)
50 }
51 if ctx.PDSEndpoint != "https://bsky.social" {
52 t.Errorf("Expected PDSEndpoint %q, got %q", "https://bsky.social", ctx.PDSEndpoint)
53 }
54 if ctx.Repository != "debian" {
55 t.Errorf("Expected Repository %q, got %q", "debian", ctx.Repository)
56 }
57 if ctx.ServiceToken != "test-token" {
58 t.Errorf("Expected ServiceToken %q, got %q", "test-token", ctx.ServiceToken)
59 }
60}
61
62func TestRegistryContext_DatabaseInterface(t *testing.T) {
63 db := &mockHoldDIDLookup{holdDID: "did:web:test-hold.example.com"}
64 ctx := &RegistryContext{
65 Database: db,
66 }
67
68 // Test that interface method is callable
69 holdDID, err := ctx.Database.GetLatestHoldDIDForRepo("did:plc:test", "repo")
70 if err != nil {
71 t.Errorf("Unexpected error: %v", err)
72 }
73 if holdDID != "did:web:test-hold.example.com" {
74 t.Errorf("Expected holdDID %q, got %q", "did:web:test-hold.example.com", holdDID)
75 }
76}
77
78// TODO: Add more comprehensive tests:
79// - Test ATProtoClient integration
80// - Test OAuth Refresher integration
81// - Test HoldAuthorizer integration
82// - Test nil handling for optional fields
83// - Integration tests with real components