Files
moloapp/tests/example/agent/registry/cases.hpp
T

40 lines
1.5 KiB
C++
Raw Normal View History

#pragma once
// Shared case for the registry route tests (not a test itself). Every route
// that would call Google is a POST that must: answer 503 google_not_configured
// without a credential, answer 422 validation_error on bad input before any
// upstream call, and answer 405 to GET.
#include <cstdlib>
#include <string>
#include "support/GoogleRig.hpp"
namespace molo::example::test {
inline void check_google_post_route(const std::string& path, const std::string& good_body,
const std::string& bad_body, const std::string& what) {
setenv("GOOGLE_CLOUD_PROJECT", "test-project", 1);
const std::string json = "application/json";
{
GoogleRig rig(false);
Fixture f(rig.client);
auto res = f.client->post(path, good_body, json);
check(res.status == 503, path + ": no credential is 503");
check(contains(res.body, "google_not_configured"), "error code google_not_configured");
check(contains(res.headers.get("Content-Type"), "application/json"), "error body is json");
check(rig.mock->send_count() == 0, "side effect: no upstream traffic");
}
{
GoogleRig rig;
Fixture f(rig.client);
auto res = f.client->post(path, bad_body, json);
check(res.status == 422, path + ": " + what + " is 422");
check(contains(res.body, "validation_error"), "error code validation_error");
check(rig.mock->send_count() == 0, "side effect: rejected before any upstream call");
check(f.client->get(path).status == 405, path + ": get is 405");
}
}
} // namespace molo::example::test