ytdlp_flags_test.go
⎇
Raw
1package service
2
3import (
4 "testing"
5)
6
7func TestCheckReservedFlags(t *testing.T) {
8 cases := []struct {
9 name string
10 flags string
11 subscription bool
12 wantErr bool
13 }{
14 {"empty", "", false, false},
15 {"harmless", "--no-playlist --write-thumbnail", false, false},
16 {"output short", "-o foo.mp4", false, true},
17 {"output long", "--output foo.mp4", false, true},
18 {"output equals form", "--output=foo.mp4", false, true},
19 {"paths short", "-P /tmp", false, true},
20 {"cookies", "--cookies x.txt", false, true},
21 {"cookies inverse", "--no-cookies", false, true},
22 // Subscription-only reserved flags pass for normal downloads...
23 {"skip-download non-sub", "--skip-download", false, false},
24 {"write-info-json non-sub", "--write-info-json", false, false},
25 // ...but are rejected for subscription runs (and their inverses).
26 {"skip-download sub", "--skip-download", true, true},
27 {"no-skip-download sub", "--no-skip-download", true, true},
28 {"write-info-json sub", "--write-info-json", true, true},
29 {"no-write-info-json sub", "--no-write-info-json", true, true},
30 {"download-archive sub", "--download-archive a.txt", true, true},
31 // The "--flag=value" spelling names the same option as "--flag value",
32 // for the subscription-only table as well as the base one.
33 {"download-archive equals form sub", "--download-archive=a.txt", true, true},
34 // Base reserved flags still apply to subscriptions.
35 {"output sub", "-o x", true, true},
36 {"playlist metafiles", "--write-playlist-metafiles", false, true},
37 // A quoted value is one token, so its contents cannot look like a flag.
38 {"quoted value", `--match-filter "duration > 60"`, false, false},
39 {"quoted value hiding a reserved flag", `--match-filter "-o x"`, false, false},
40 // Malformed quoting must fail the download instead of being split anyway.
41 {"unterminated quote", `--match-filter "duration > 60`, false, true},
42 }
43 for _, tc := range cases {
44 t.Run(tc.name, func(t *testing.T) {
45 err := checkReservedFlags(tc.flags, tc.subscription)
46 if tc.wantErr != (err != nil) {
47 t.Errorf("checkReservedFlags(%q, %v) error = %v, wantErr %v", tc.flags, tc.subscription, err, tc.wantErr)
48 }
49 })
50 }
51}
52