161 lines
3.8 KiB
Go
161 lines
3.8 KiB
Go
package archiver
|
|
|
|
import (
|
|
"context"
|
|
"testing"
|
|
)
|
|
|
|
func TestThumbnailArchiver_GetDefaultConfig(t *testing.T) {
|
|
archiver := NewThumbnailExtractor()
|
|
config := archiver.GetDefaultConfig()
|
|
|
|
configMap, ok := config.(map[string]any)
|
|
if !ok {
|
|
t.Fatalf("Expected config to be map[string]any, got %T", config)
|
|
}
|
|
|
|
// Check that resize is false by default
|
|
resize, ok := configMap["resize"]
|
|
if !ok {
|
|
t.Error("Expected 'resize' key in default config")
|
|
}
|
|
if resize != false {
|
|
t.Errorf("Expected resize to be false by default, got %v", resize)
|
|
}
|
|
|
|
// Check that timeout is present
|
|
timeout, ok := configMap["timeout"]
|
|
if !ok {
|
|
t.Error("Expected 'timeout' key in default config")
|
|
}
|
|
if timeout != "5m" {
|
|
t.Errorf("Expected timeout to be '5m', got %v", timeout)
|
|
}
|
|
}
|
|
|
|
func TestThumbnailArchiver_ApplyConfig_Resize(t *testing.T) {
|
|
archiver := NewThumbnailExtractor()
|
|
|
|
// Test setting resize to true
|
|
config := map[string]any{
|
|
"resize": true,
|
|
}
|
|
err := archiver.ApplyConfig(config)
|
|
if err != nil {
|
|
t.Fatalf("ApplyConfig failed: %v", err)
|
|
}
|
|
if !archiver.resize {
|
|
t.Error("Expected resize to be true after ApplyConfig")
|
|
}
|
|
|
|
// Test setting resize to false
|
|
config = map[string]any{
|
|
"resize": false,
|
|
}
|
|
err = archiver.ApplyConfig(config)
|
|
if err != nil {
|
|
t.Fatalf("ApplyConfig failed: %v", err)
|
|
}
|
|
if archiver.resize {
|
|
t.Error("Expected resize to be false after ApplyConfig")
|
|
}
|
|
}
|
|
|
|
func TestThumbnailArchiver_ApplyConfig_InvalidResize(t *testing.T) {
|
|
archiver := NewThumbnailExtractor()
|
|
|
|
// Test invalid resize type (string instead of bool)
|
|
config := map[string]any{
|
|
"resize": "true",
|
|
}
|
|
err := archiver.ApplyConfig(config)
|
|
if err == nil {
|
|
t.Error("Expected error for invalid resize type")
|
|
}
|
|
if err.Error() != "invalid resize format: expected boolean" {
|
|
t.Errorf("Expected specific error message, got: %v", err)
|
|
}
|
|
}
|
|
|
|
func TestThumbnailArchiver_ApplyConfig_Timeout(t *testing.T) {
|
|
archiver := NewThumbnailExtractor()
|
|
|
|
// Test setting timeout
|
|
config := map[string]any{
|
|
"timeout": "10m",
|
|
}
|
|
err := archiver.ApplyConfig(config)
|
|
if err != nil {
|
|
t.Fatalf("ApplyConfig failed: %v", err)
|
|
}
|
|
if archiver.httpClient.Timeout.String() != "10m0s" {
|
|
t.Errorf("Expected timeout to be 10m, got %v", archiver.httpClient.Timeout)
|
|
}
|
|
}
|
|
|
|
func TestThumbnailArchiver_ApplyConfig_InvalidTimeout(t *testing.T) {
|
|
archiver := NewThumbnailExtractor()
|
|
|
|
// Test invalid timeout format
|
|
config := map[string]any{
|
|
"timeout": "invalid",
|
|
}
|
|
err := archiver.ApplyConfig(config)
|
|
if err == nil {
|
|
t.Error("Expected error for invalid timeout format")
|
|
}
|
|
}
|
|
|
|
func TestThumbnailArchiver_ApplyConfig_ResizeAndTimeout(t *testing.T) {
|
|
archiver := NewThumbnailExtractor()
|
|
|
|
// Test setting both resize and timeout
|
|
config := map[string]any{
|
|
"resize": true,
|
|
"timeout": "15m",
|
|
}
|
|
err := archiver.ApplyConfig(config)
|
|
if err != nil {
|
|
t.Fatalf("ApplyConfig failed: %v", err)
|
|
}
|
|
if !archiver.resize {
|
|
t.Error("Expected resize to be true")
|
|
}
|
|
if archiver.httpClient.Timeout.String() != "15m0s" {
|
|
t.Errorf("Expected timeout to be 15m, got %v", archiver.httpClient.Timeout)
|
|
}
|
|
}
|
|
|
|
func TestThumbnailArchiver_Key(t *testing.T) {
|
|
archiver := NewThumbnailExtractor()
|
|
|
|
if archiver.Key() != "thumbnail" {
|
|
t.Errorf("Expected key 'thumbnail', got %s", archiver.Key())
|
|
}
|
|
}
|
|
|
|
func TestThumbnailArchiver_Name(t *testing.T) {
|
|
archiver := NewThumbnailExtractor()
|
|
|
|
if archiver.Name() != "Thumbnail" {
|
|
t.Errorf("Expected name 'Thumbnail', got %s", archiver.Name())
|
|
}
|
|
}
|
|
|
|
func TestThumbnailArchiver_IsEnabled(t *testing.T) {
|
|
archiver := NewThumbnailExtractor()
|
|
ctx := context.Background()
|
|
|
|
if !archiver.IsEnabled(ctx) {
|
|
t.Error("Thumbnail archiver should always be enabled")
|
|
}
|
|
}
|
|
|
|
func TestThumbnailArchiver_Init(t *testing.T) {
|
|
archiver := NewThumbnailExtractor()
|
|
|
|
err := archiver.Init()
|
|
if err != nil {
|
|
t.Errorf("Init should not return an error, got: %v", err)
|
|
}
|
|
}
|