Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE-29] Add integration tests #30

Merged
merged 3 commits into from
Oct 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,7 @@ jobs:
- name: Unit tests
run: dub test --coverage

- name: e2e tests
run: sh tests.sh


13 changes: 8 additions & 5 deletions source/app.d
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ void main(string[] args)
bool parallel;
bool outputURL;
bool verbose;
bool noProgress;

auto help = args.getopt(
std.getopt.config.passThrough,
Expand All @@ -28,7 +29,8 @@ void main(string[] args)
"F", "List available formats", &displayFormats,
"o|output-url", "Display extracted video URL without downloading it", &outputURL,
"p|parallel", "Download in 4 parallel connections", &parallel,
"v|verbose", "Display debugging messages", &verbose
"v|verbose", "Display debugging messages", &verbose,
"no-progress", "Don't display real-time progress", &noProgress
);

if(help.helpWanted || args.length == 1)
Expand All @@ -52,7 +54,8 @@ void main(string[] args)
logger,
displayFormats,
outputURL,
parallel
parallel,
noProgress
);
}
catch(Exception e)
Expand All @@ -69,7 +72,7 @@ void main(string[] args)
}
}

void handleURL(string url, int itag, StdoutLogger logger, bool displayFormats, bool outputURL, bool parallel)
void handleURL(string url, int itag, StdoutLogger logger, bool displayFormats, bool outputURL, bool parallel, bool noProgress)
{
logger.display(formatTitle("Handling " ~ url));
string html = url.get().idup;
Expand Down Expand Up @@ -113,7 +116,7 @@ void handleURL(string url, int itag, StdoutLogger logger, bool displayFormats, b
if(parallel)
{
logger.display("Using ParallelDownloader");
downloader = new ParallelDownloader(logger, parser.getID(), parser.getTitle(), youtubeFormat);
downloader = new ParallelDownloader(logger, parser.getID(), parser.getTitle(), youtubeFormat, !noProgress);
}
else
{
Expand All @@ -130,7 +133,7 @@ void handleURL(string url, int itag, StdoutLogger logger, bool displayFormats, b
auto percentage = 100.0 * (cast(float)(current) / total);
writef!"\r[%.2f %%] %.2f / %.2f MB"(percentage, current / 1024.0 / 1024.0, total / 1024.0 / 1024.0);
return 0;
});
}, !noProgress);
}
downloader.download(destination, link, url);
}
19 changes: 13 additions & 6 deletions source/downloaders.d
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,13 @@ class RegularDownloader : Downloader
{
private StdoutLogger logger;
private int delegate(ulong length, ulong currentLength) onProgress;
private bool progress;

this(StdoutLogger logger, int delegate(ulong length, ulong currentLength) onProgress)
this(StdoutLogger logger, int delegate(ulong length, ulong currentLength) onProgress, bool progress = true)
{
this.logger = logger;
this.onProgress = onProgress;
this.progress = progress;
}

public void download(string destination, string url, string referer)
Expand All @@ -48,9 +50,12 @@ class RegularDownloader : Downloader
return data.length;
};

http.onProgress = (size_t total, size_t current, size_t _, size_t __) {
return onProgress(total, current);
};
if(progress)
{
http.onProgress = (size_t total, size_t current, size_t _, size_t __) {
return onProgress(total, current);
};
}
auto result = http.perform();
}
}
Expand All @@ -61,13 +66,15 @@ class ParallelDownloader : Downloader
private string id;
private string title;
private YoutubeFormat youtubeFormat;
private bool progress;

this(StdoutLogger logger, string id, string title, YoutubeFormat youtubeFormat)
this(StdoutLogger logger, string id, string title, YoutubeFormat youtubeFormat, bool progress = true)
{
this.id = id;
this.title = title;
this.logger = logger;
this.youtubeFormat = youtubeFormat;
this.progress = progress;
}

public void download(string destination, string url, string referer)
Expand Down Expand Up @@ -100,7 +107,7 @@ class ParallelDownloader : Downloader
auto percentage = 100.0 * (cast(float)(current) / length);
writef!"\r[%.2f %%] %.2f / %.2f MB"(percentage, current / 1024.0 / 1024.0, length / 1024.0 / 1024.0);
return 0;
}).download(partialDestination, partialLink, url);
}, progress).download(partialDestination, partialLink, url);
}

writeln();
Expand Down
25 changes: 25 additions & 0 deletions tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
./youtube-d -p --no-progress https://www.youtube.com/watch?v=R85MK830mMo

filename="Debugging Github actions-R85MK830mMo-18.mp4"
if [ ! -e "$filename" ]; then
echo "$filename not found"
exit 1
fi
echo "[1/3] OK, $filename exists"

expected_size=5953988
actual_size=$(du -b "$filename" | cut -f 1)
if [ $expected_size -ne $actual_size ]; then
echo "Wrong size. Expected $expected_size, found $actual_size"
exit 1
fi
echo "[2/3] OK, size is correct"

expected_hash="b264ca23f70ff08105af6309d3d2f4ed"
actual_hash=$(md5sum "$filename" | cut -d " " -f 1)
if [ $expected_hash != $actual_hash ]; then
echo "Wrong hash. Expected $expected_hash, found $actual_hash"
exit 1
fi

echo "[3/3] OK, md5sum is correct"
Loading