46 lines
1.1 KiB
Go
46 lines
1.1 KiB
Go
package dyzurbot
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestLoadConfigDefaults(t *testing.T) {
|
|
t.Setenv("SPREADSHEET_ID", "sheet-123")
|
|
t.Setenv("SHEET_RANGE", "")
|
|
t.Setenv("ROTA_CACHE_PATH", "")
|
|
t.Setenv("SYNC_INTERVAL", "")
|
|
|
|
cfg, err := LoadConfig()
|
|
if err != nil {
|
|
t.Fatalf("LoadConfig: %v", err)
|
|
}
|
|
if cfg.SpreadsheetID != "sheet-123" {
|
|
t.Errorf("SpreadsheetID: got %q", cfg.SpreadsheetID)
|
|
}
|
|
if cfg.SheetRange != "Dyżury!A1:F100" {
|
|
t.Errorf("SheetRange default: got %q", cfg.SheetRange)
|
|
}
|
|
if cfg.CachePath != "rota.json" {
|
|
t.Errorf("CachePath default: got %q", cfg.CachePath)
|
|
}
|
|
if cfg.SyncInterval != 30*time.Minute {
|
|
t.Errorf("SyncInterval default: got %v", cfg.SyncInterval)
|
|
}
|
|
}
|
|
|
|
func TestLoadConfigRequiresSpreadsheetID(t *testing.T) {
|
|
t.Setenv("SPREADSHEET_ID", "")
|
|
if _, err := LoadConfig(); err == nil {
|
|
t.Fatal("expected error when SPREADSHEET_ID is missing")
|
|
}
|
|
}
|
|
|
|
func TestLoadConfigRejectsBadInterval(t *testing.T) {
|
|
t.Setenv("SPREADSHEET_ID", "sheet-123")
|
|
t.Setenv("SYNC_INTERVAL", "not-a-duration")
|
|
if _, err := LoadConfig(); err == nil {
|
|
t.Fatal("expected error for unparseable SYNC_INTERVAL")
|
|
}
|
|
}
|