gopro-ingester/source/app.d

85 lines
2.2 KiB
D
Raw Permalink Normal View History

2022-11-10 15:58:30 +00:00
import utils;
import ingest;
2022-11-10 10:17:31 +00:00
int main(string[] args) {
2022-11-11 10:40:35 +00:00
printBanner();
CliResult result = parseArgs(args);
if (result.type == CliResultType.NO_CONTENT) {
2022-11-10 10:17:31 +00:00
return 0;
2022-11-11 10:40:35 +00:00
} else if (result.type == CliResultType.MISSING_MEDIA) {
return 1;
} else {
return copyFiles(result.config);
2022-11-10 10:17:31 +00:00
}
2022-11-11 10:40:35 +00:00
}
2022-11-10 10:17:31 +00:00
2022-11-11 10:40:35 +00:00
unittest {
// First some utilities to make the tests simpler.
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;
}
int callApp(string[] args ...) {
return main(["app"] ~ args);
2022-11-10 10:17:31 +00:00
}
2022-11-11 10:40:35 +00:00
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));
}
}
string[] allCards = ["1", "2", "3"];
prepareCardTests(allCards);
writeln(isDir(getBaseCardDir("1")));
assert(callApp("-h") == 0);
assertCardsUnchanged(allCards);
assert(callApp("--help") == 0);
assertCardsUnchanged(allCards);
assert(callApp("-f", "-h") == 0);
assertCardsUnchanged(allCards);
// Ingesting from an empty card shouldn't have any effect.
assert(callApp("-i", getTestCardDir("1")) == 0);
assertCardsUnchanged("1");
2022-11-10 10:17:31 +00:00
}