mirror of
https://tangled.org/evan.jarrett.net/at-container-registry
synced 2026-04-21 00:50:29 +00:00
89 lines
2.6 KiB
Go
89 lines
2.6 KiB
Go
package storage
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"atcr.io/pkg/atproto"
|
|
)
|
|
|
|
// Mock implementations for testing
|
|
|
|
// mockHoldDIDLookup implements HoldDIDLookup for testing
|
|
type mockHoldDIDLookup struct {
|
|
holdDID string // Return value for GetLatestHoldDIDForRepo
|
|
}
|
|
|
|
func (m *mockHoldDIDLookup) GetLatestHoldDIDForRepo(did, repository string) (string, error) {
|
|
return m.holdDID, nil
|
|
}
|
|
|
|
func (m *mockHoldDIDLookup) UpdateManifestHoldDID(did, oldHoldDID, newHoldDID string) (int64, error) {
|
|
return 0, nil
|
|
}
|
|
|
|
func (m *mockHoldDIDLookup) GetDistinctManifestHoldDIDs(did string) ([]string, error) {
|
|
if m.holdDID != "" {
|
|
return []string{m.holdDID}, nil
|
|
}
|
|
return nil, nil
|
|
}
|
|
|
|
func TestRegistryContext_Fields(t *testing.T) {
|
|
// Create a sample RegistryContext
|
|
ctx := &RegistryContext{
|
|
DID: "did:plc:test123",
|
|
Handle: "alice.bsky.social",
|
|
HoldDID: "did:web:hold01.atcr.io",
|
|
PDSEndpoint: "https://bsky.social",
|
|
Repository: "debian",
|
|
ServiceToken: "test-token",
|
|
ATProtoClient: &atproto.Client{
|
|
// Mock client - would need proper initialization in real tests
|
|
},
|
|
Database: &mockHoldDIDLookup{holdDID: "did:web:hold01.atcr.io"},
|
|
}
|
|
|
|
// Verify fields are accessible
|
|
if ctx.DID != "did:plc:test123" {
|
|
t.Errorf("Expected DID %q, got %q", "did:plc:test123", ctx.DID)
|
|
}
|
|
if ctx.Handle != "alice.bsky.social" {
|
|
t.Errorf("Expected Handle %q, got %q", "alice.bsky.social", ctx.Handle)
|
|
}
|
|
if ctx.HoldDID != "did:web:hold01.atcr.io" {
|
|
t.Errorf("Expected HoldDID %q, got %q", "did:web:hold01.atcr.io", ctx.HoldDID)
|
|
}
|
|
if ctx.PDSEndpoint != "https://bsky.social" {
|
|
t.Errorf("Expected PDSEndpoint %q, got %q", "https://bsky.social", ctx.PDSEndpoint)
|
|
}
|
|
if ctx.Repository != "debian" {
|
|
t.Errorf("Expected Repository %q, got %q", "debian", ctx.Repository)
|
|
}
|
|
if ctx.ServiceToken != "test-token" {
|
|
t.Errorf("Expected ServiceToken %q, got %q", "test-token", ctx.ServiceToken)
|
|
}
|
|
}
|
|
|
|
func TestRegistryContext_DatabaseInterface(t *testing.T) {
|
|
db := &mockHoldDIDLookup{holdDID: "did:web:test-hold.example.com"}
|
|
ctx := &RegistryContext{
|
|
Database: db,
|
|
}
|
|
|
|
// Test that interface method is callable
|
|
holdDID, err := ctx.Database.GetLatestHoldDIDForRepo("did:plc:test", "repo")
|
|
if err != nil {
|
|
t.Errorf("Unexpected error: %v", err)
|
|
}
|
|
if holdDID != "did:web:test-hold.example.com" {
|
|
t.Errorf("Expected holdDID %q, got %q", "did:web:test-hold.example.com", holdDID)
|
|
}
|
|
}
|
|
|
|
// TODO: Add more comprehensive tests:
|
|
// - Test ATProtoClient integration
|
|
// - Test OAuth Refresher integration
|
|
// - Test HoldAuthorizer integration
|
|
// - Test nil handling for optional fields
|
|
// - Integration tests with real components
|