gopro-ingester/source/testutils.d

51 lines
1.1 KiB
D
Raw Permalink Normal View History

2022-11-11 10:40:35 +00:00
module testutils;
import std.stdio;
import std.file;
import std.path;
import std.algorithm;
import std.string;
import utils;
struct DirView {
DirEntry[] entries;
}
DirView getDirView(string dir) {
DirView view;
foreach (DirEntry entry; dirEntries(dir, SpanMode.shallow)) {
view.entries ~= entry;
}
view.entries.sort!((a, b) => a.name > b.name);
return view;
}
string getBaseCardDir(string name) {
return buildPath("test", "media-cards", "card-" ~ name);
}
string getTestCardDir(string name) {
return buildPath("test", "media-cards", "card-test-" ~ name);
}
void assertCardsUnchanged(string[] cards ...) {
foreach (string card; cards) {
string baseDir = getBaseCardDir(card);
string testDir = getTestCardDir(card);
if (exists(testDir)) {
assert(getDirView(baseDir) == getDirView(testDir));
}
}
}
void prepareCardTests(string[] cards ...) {
foreach (string card; cards) {
copyDir(getBaseCardDir(card), getTestCardDir(card));
}
}
void cleanupCardTests(string[] cards ...) {
foreach (string card; cards) {
rmdirRecurse(getTestCardDir(card));
}
}