From c5d1b359553356a3ec56e3a4850e3c83bbccaffd Mon Sep 17 00:00:00 2001 From: Justin Hawkins Date: Thu, 6 Jan 2022 00:03:48 +1030 Subject: [PATCH] Improve testing across the max downloads per domain. --- download/download_test.go | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/download/download_test.go b/download/download_test.go index 2594f53..aa0f2b4 100644 --- a/download/download_test.go +++ b/download/download_test.go @@ -68,9 +68,9 @@ func TestUpdateMetadata(t *testing.T) { func TestQueue(t *testing.T) { conf := config.TestConfig() - new1 := Download{Id: 1, State: "queued", DownloadProfile: conf.DownloadProfiles[0], Config: conf} - new2 := Download{Id: 2, State: "queued", DownloadProfile: conf.DownloadProfiles[0], Config: conf} - new3 := Download{Id: 3, State: "queued", DownloadProfile: conf.DownloadProfiles[0], Config: conf} + new1 := Download{Id: 1, Url: "http://domain1.com/foo", State: "queued", DownloadProfile: conf.DownloadProfiles[0], Config: conf} + new2 := Download{Id: 2, Url: "http://domain1.com/foo", State: "queued", DownloadProfile: conf.DownloadProfiles[0], Config: conf} + new3 := Download{Id: 3, Url: "http://domain1.com/foo", State: "queued", DownloadProfile: conf.DownloadProfiles[0], Config: conf} new4 := Download{Id: 4, Url: "http://company.org/", State: "queued", DownloadProfile: conf.DownloadProfiles[0], Config: conf} dls := Downloads{&new1, &new2, &new3, &new4} @@ -101,4 +101,30 @@ func TestQueue(t *testing.T) { t.Error("#4 was not started but it should be") } + // reset them all + dls[0].State = "queued" + dls[1].State = "queued" + dls[2].State = "queued" + dls[3].State = "queued" + + dls.StartQueued(0) + + // they should all be going + if dls[0].State == "queued" || dls[1].State == "queued" || dls[2].State == "queued" || dls[3].State == "queued" { + t.Error("none should be queued") + } + + // reset them all + dls[0].State = "queued" + dls[1].State = "queued" + dls[2].State = "queued" + dls[3].State = "queued" + + dls.StartQueued(2) + + // first two should be running, third not (same domain) and 4th running (different domain) + if dls[0].State == "queued" || dls[1].State == "queued" || dls[2].State != "queued" || dls[3].State == "queued" { + t.Error("incorrect queued") + } + }