mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-06-17 15:05:39 +02:00
harden search parsing and qobuz refresh validation
This commit is contained in:
@@ -2,6 +2,9 @@ package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
@@ -198,6 +201,38 @@ func TestParseSearchArgsAllowsFirstAndOutputFileButCallerCanReject(t *testing.T)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSearchArgsRejectsUnknownOption(t *testing.T) {
|
||||
_, err := parseSearchArgs([]string{"query", "--bogus"}, 20)
|
||||
if err == nil || !strings.Contains(err.Error(), "unknown option") {
|
||||
t.Fatalf("expected unknown option error, got %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseSearchArgsSupportsDoubleDashTerminator(t *testing.T) {
|
||||
opts, err := parseSearchArgs([]string{"--limit", "10", "--", "--weird", "track"}, 20)
|
||||
if err != nil {
|
||||
t.Fatalf("parseSearchArgs() error = %v", err)
|
||||
}
|
||||
if opts.limit != 10 {
|
||||
t.Fatalf("limit = %d, want 10", opts.limit)
|
||||
}
|
||||
if opts.query != "--weird track" {
|
||||
t.Fatalf("query = %q, want %q", opts.query, "--weird track")
|
||||
}
|
||||
}
|
||||
|
||||
func TestWriteSearchResultsToFileCreatesParentDirectory(t *testing.T) {
|
||||
tmp := t.TempDir()
|
||||
out := filepath.Join(tmp, "nested", "search", "results.json")
|
||||
results := []searchResult{{ID: "1", Title: "Dreams"}}
|
||||
if err := writeSearchResultsToFile("qobuz", "track", results, out); err != nil {
|
||||
t.Fatalf("writeSearchResultsToFile() error = %v", err)
|
||||
}
|
||||
if _, err := os.Stat(out); err != nil {
|
||||
t.Fatalf("expected output file, stat error = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestErrorWithActionableHintForSSL(t *testing.T) {
|
||||
err := errors.New("x509: certificate signed by unknown authority")
|
||||
msg := errorWithActionableHint(err, globalOptions{})
|
||||
|
||||
Reference in New Issue
Block a user