hako/internal/archival/archiver/obelisk_test.go
Felipe M. d9f63a5eee
Some checks failed
CI / goreleaser-lint (push) Successful in 9s
CI / format (push) Successful in 1m1s
CI / lint (push) Successful in 4m43s
CI / test (push) Successful in 6m26s
CI / build (push) Successful in 6m40s
Release / release (push) Failing after 5m0s
CI / e2e (push) Successful in 25m10s
fix: tolerate unreachable sub-resources in obelisk archiver
Enable skip_resource_url_error by default so a blocked or unresolvable
sub-resource (trackers, CDN assets) no longer aborts the whole archival.

Archiver defaults are extracted to constants and applyConfigToArchiver
merges the provided config over them, so a stored config missing a key
uses the default instead of inheriting the shared archiver state from a
previous run.
2026-09-22 20:45:07 +02:00

69 lines
2.3 KiB
Go

package archiver
import (
"testing"
"time"
)
func TestObeliskArchiver_GetDefaultConfig(t *testing.T) {
archiver := NewObeliskExtractor()
config, ok := archiver.GetDefaultConfig().(map[string]any)
if !ok {
t.Fatalf("Expected config to be map[string]any, got %T", archiver.GetDefaultConfig())
}
if config["skip_resource_url_error"] != true {
t.Errorf("Expected skip_resource_url_error to be true by default, got %v", config["skip_resource_url_error"])
}
if config["timeout"] != "5m0s" {
t.Errorf("Expected timeout to be '5m0s', got %v", config["timeout"])
}
if config["user_agent"] != "Hako/1.0" {
t.Errorf("Expected user_agent to be 'Hako/1.0', got %v", config["user_agent"])
}
}
func TestObeliskArchiver_NewAppliesDefaults(t *testing.T) {
archiver := NewObeliskExtractor()
if !archiver.archiver.SkipResourceURLError {
t.Error("Expected SkipResourceURLError to be enabled on a new archiver")
}
if archiver.archiver.RequestTimeout != 5*time.Minute {
t.Errorf("Expected RequestTimeout of 5m, got %v", archiver.archiver.RequestTimeout)
}
if archiver.archiver.MaxConcurrentDownload != 10 {
t.Errorf("Expected MaxConcurrentDownload of 10, got %d", archiver.archiver.MaxConcurrentDownload)
}
}
func TestObeliskArchiver_ApplyConfig_PartialConfigKeepsDefaults(t *testing.T) {
archiver := NewObeliskExtractor()
if err := archiver.ApplyConfig(map[string]any{"skip_resource_url_error": false}); err != nil {
t.Fatalf("ApplyConfig failed: %v", err)
}
if archiver.archiver.SkipResourceURLError {
t.Error("Expected SkipResourceURLError to be disabled by explicit config")
}
// A later config omitting the key must fall back to the default, not to the
// value left over from the previous archival.
if err := archiver.ApplyConfig(map[string]any{"timeout": "30s"}); err != nil {
t.Fatalf("ApplyConfig failed: %v", err)
}
if !archiver.archiver.SkipResourceURLError {
t.Error("Expected SkipResourceURLError to fall back to the default")
}
if archiver.archiver.RequestTimeout != 30*time.Second {
t.Errorf("Expected RequestTimeout of 30s, got %v", archiver.archiver.RequestTimeout)
}
}
func TestObeliskArchiver_ApplyConfig_InvalidTimeout(t *testing.T) {
archiver := NewObeliskExtractor()
if err := archiver.ApplyConfig(map[string]any{"timeout": "not-a-duration"}); err == nil {
t.Error("Expected an error for an invalid timeout value")
}
}