test: add download, store, and scraper tests

This commit is contained in:
Mathis Maquenne
2026-08-05 11:50:30 +02:00
parent 563efe78bd
commit 3fe050ea15
5 changed files with 266 additions and 0 deletions
+39
View File
@@ -0,0 +1,39 @@
package download
import (
"testing"
"time"
)
func TestOptionsValidate(t *testing.T) {
valid := Options{Quality: "mp3_320", Timeout: time.Minute, Limit: 10}
tests := []struct {
name string
mutate func(o *Options)
wantErr bool
}{
{"valid", func(o *Options) {}, false},
{"mp3_128", func(o *Options) { o.Quality = "mp3_128" }, false},
{"flac", func(o *Options) { o.Quality = "flac" }, false},
{"invalid quality", func(o *Options) { o.Quality = "ogg" }, true},
{"uppercase quality", func(o *Options) { o.Quality = "MP3_320" }, true},
{"zero timeout", func(o *Options) { o.Timeout = 0 }, true},
{"negative timeout", func(o *Options) { o.Timeout = -time.Second }, true},
{"zero limit", func(o *Options) { o.Limit = 0 }, true},
{"limit too high", func(o *Options) { o.Limit = 101 }, true},
{"limit at max", func(o *Options) { o.Limit = 100 }, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
opts := valid
tt.mutate(&opts)
err := opts.Validate()
if (err != nil) != tt.wantErr {
t.Errorf("Validate() error = %v, wantErr %v", err, tt.wantErr)
}
})
}
}