Files
moloapp/tests/example/matrix_test.cpp
T

28 lines
1.1 KiB
C++

// Route: GET / (every matrix link resolves; no dead rows)
#include "support/Assert.hpp"
using namespace molo::example::test;
int main() {
Fixture f;
auto index = f.client->get("/");
check(index.status == 200, "index renders");
std::size_t pos = 0, rows = 0;
const std::string marker = "<td><a href=\"";
while ((pos = index.body.find(marker, pos)) != std::string::npos) {
pos += marker.size();
std::string href = index.body.substr(pos, index.body.find('"', pos) - pos);
// The template escapes '&' in hrefs.
for (std::size_t a; (a = href.find("&amp;")) != std::string::npos;)
href.replace(a, 5, "&");
if (href.rfind("http", 0) == 0) continue; // external (locust UI), not a route
auto res = f.client->get(href);
// /auth/me demands credentials by design; every other row must be 2xx/3xx.
bool ok = res.status < 400 || (href == "/auth/me" && res.status == 401);
check(ok, "matrix link " + href + " -> " + std::to_string(res.status));
++rows;
}
check(rows >= 37, "matrix lists at least the original 37 rows");
return finish("matrix");
}