ytdlp_flags_test.go
| 1 | package service |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | ) |
| 6 | |
| 7 | func 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 | } |
| 37 | for _, tc := range cases { |
| 38 | t.Run(tc.name, func(t *testing.T) { |
| 39 | err := checkReservedFlags(tc.flags, tc.subscription) |
| 40 | if tc.wantErr != (err != nil) { |
| 41 | t.Errorf("checkReservedFlags(%q, %v) error = %v, wantErr %v", tc.flags, tc.subscription, err, tc.wantErr) |
| 42 | } |
| 43 | }) |
| 44 | } |
| 45 | } |
| 46 |