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") } }