package service import ( "testing" ) func TestCheckReservedFlags(t *testing.T) { cases := []struct { name string flags string subscription bool wantErr bool }{ {"empty", "", false, false}, {"harmless", "--no-playlist --write-thumbnail", false, false}, {"output short", "-o foo.mp4", false, true}, {"output long", "--output foo.mp4", false, true}, {"output equals form", "--output=foo.mp4", false, true}, {"paths short", "-P /tmp", false, true}, {"cookies", "--cookies x.txt", false, true}, {"cookies inverse", "--no-cookies", false, true}, // Subscription-only reserved flags pass for normal downloads... {"skip-download non-sub", "--skip-download", false, false}, {"write-info-json non-sub", "--write-info-json", false, false}, // ...but are rejected for subscription runs (and their inverses). {"skip-download sub", "--skip-download", true, true}, {"no-skip-download sub", "--no-skip-download", true, true}, {"write-info-json sub", "--write-info-json", true, true}, {"no-write-info-json sub", "--no-write-info-json", true, true}, {"download-archive sub", "--download-archive a.txt", true, true}, // The "--flag=value" spelling names the same option as "--flag value", // for the subscription-only table as well as the base one. {"download-archive equals form sub", "--download-archive=a.txt", true, true}, // Base reserved flags still apply to subscriptions. {"output sub", "-o x", true, true}, {"playlist metafiles", "--write-playlist-metafiles", false, true}, // A quoted value is one token, so its contents cannot look like a flag. {"quoted value", `--match-filter "duration > 60"`, false, false}, {"quoted value hiding a reserved flag", `--match-filter "-o x"`, false, false}, // Malformed quoting must fail the download instead of being split anyway. {"unterminated quote", `--match-filter "duration > 60`, false, true}, } for _, tc := range cases { t.Run(tc.name, func(t *testing.T) { err := checkReservedFlags(tc.flags, tc.subscription) if tc.wantErr != (err != nil) { t.Errorf("checkReservedFlags(%q, %v) error = %v, wantErr %v", tc.flags, tc.subscription, err, tc.wantErr) } }) } }