mirror of
https://tangled.org/evan.jarrett.net/at-container-registry
synced 2026-09-21 01:34:16 +00:00
unit tests
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
|
||||
"atcr.io/pkg/atproto"
|
||||
)
|
||||
|
||||
// Mock implementations for testing
|
||||
type mockDatabaseMetrics struct{}
|
||||
|
||||
func (m *mockDatabaseMetrics) IncrementPullCount(did, repository string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m *mockDatabaseMetrics) IncrementPushCount(did, repository string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type mockReadmeCache struct{}
|
||||
|
||||
func (m *mockReadmeCache) Get(ctx context.Context, url string) (string, error) {
|
||||
return "# Test README", nil
|
||||
}
|
||||
|
||||
func (m *mockReadmeCache) Invalidate(url string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
type mockHoldAuthorizer struct{}
|
||||
|
||||
func (m *mockHoldAuthorizer) Authorize(holdDID, userDID, permission string) (bool, error) {
|
||||
return true, 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: &mockDatabaseMetrics{},
|
||||
ReadmeCache: &mockReadmeCache{},
|
||||
}
|
||||
|
||||
// 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 := &mockDatabaseMetrics{}
|
||||
ctx := &RegistryContext{
|
||||
Database: db,
|
||||
}
|
||||
|
||||
// Test that interface methods are callable
|
||||
err := ctx.Database.IncrementPullCount("did:plc:test", "repo")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
|
||||
err = ctx.Database.IncrementPushCount("did:plc:test", "repo")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestRegistryContext_ReadmeCacheInterface(t *testing.T) {
|
||||
cache := &mockReadmeCache{}
|
||||
ctx := &RegistryContext{
|
||||
ReadmeCache: cache,
|
||||
}
|
||||
|
||||
// Test that interface methods are callable
|
||||
content, err := ctx.ReadmeCache.Get(nil, "https://example.com/README.md")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
if content != "# Test README" {
|
||||
t.Errorf("Expected content %q, got %q", "# Test README", content)
|
||||
}
|
||||
|
||||
err = ctx.ReadmeCache.Invalidate("https://example.com/README.md")
|
||||
if err != nil {
|
||||
t.Errorf("Unexpected error: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
Reference in New Issue
Block a user