72 lines
3.0 KiB
C++
72 lines
3.0 KiB
C++
// Routes: POST /agent/optimize/synthetic, /operations/{list,get,wait,cancel},
|
|||
|
|
// DELETE /agent/optimize/operations, POST /agent/optimize/logs/write
|
||
|
|
#include <cstdlib>
|
||
|
|
#include <string>
|
||
|
|
|
||
|
|
#include "support/GoogleRig.hpp"
|
||
|
|
|
||
|
|
using namespace molo::example::test;
|
||
|
|
using molo::example::fw::Method;
|
||
|
|
|
||
|
|
namespace {
|
||
|
|
const std::string kJson = "application/json";
|
||
|
|
const std::string kEval = "projects/test-proj/locations/us-central1/onlineEvaluators/1";
|
||
|
|
const std::string kOp = kEval + "/operations/7";
|
||
|
|
|
||
|
|
struct Case {
|
||
|
|
std::string path, good, bad;
|
||
|
|
};
|
||
|
|
} // namespace
|
||
|
|
|
||
|
|
int main() {
|
||
|
|
setenv("GOOGLE_CLOUD_PROJECT", "test-proj", 1);
|
||
|
|
const Case cases[] = {
|
||
|
|
{"/agent/optimize/synthetic", "{\"request\":{\"taskDescription\":\"x\"}}", "{\"request\":{\"nope\":1}}"},
|
||
|
|
{"/agent/optimize/operations/list", "{\"evaluator\":\"" + kEval + "\"}",
|
||
|
|
"{\"evaluator\":\"projects/p/locations/l/evaluationRuns/r\"}"},
|
||
|
|
{"/agent/optimize/operations/get", "{\"name\":\"" + kOp + "\"}", "{\"name\":\"operations/7\"}"},
|
||
|
|
{"/agent/optimize/operations/wait", "{\"name\":\"" + kOp + "\",\"timeout_seconds\":\"60\"}",
|
||
|
|
"{\"name\":\"" + kOp + "\",\"timeout_seconds\":\"61\"}"},
|
||
|
|
{"/agent/optimize/operations/cancel", "{\"name\":\"" + kOp + "\"}", "{\"name\":\"\"}"},
|
||
|
|
{"/agent/optimize/logs/write", "{\"log_id\":\"agent-check\",\"text\":\"hello\"}",
|
||
|
|
"{\"log_id\":\"a/b\",\"text\":\"hello\"}"},
|
||
|
|
};
|
||
|
|
for (const Case& c : cases) {
|
||
|
|
{
|
||
|
|
GoogleRig none(false);
|
||
|
|
Fixture f(none.client);
|
||
|
|
auto res = f.client->post(c.path, c.good, kJson);
|
||
|
|
check(res.status == 503 && contains(res.body, "google_not_configured"),
|
||
|
|
c.path + ": no credential is a loud 503");
|
||
|
|
check(none.mock->send_count() == 0, c.path + ": no network without a credential");
|
||
|
|
}
|
||
|
|
{
|
||
|
|
GoogleRig keyed;
|
||
|
|
Fixture f(keyed.client);
|
||
|
|
auto res = f.client->post(c.path, c.bad, kJson);
|
||
|
|
check(res.status == 422 && contains(res.body, "validation_error"), c.path + ": bad input is 422");
|
||
|
|
check(f.client->get(c.path).status == 405, c.path + ": get is 405");
|
||
|
|
check(keyed.mock->send_count() == 0, c.path + ": rejected before any upstream call");
|
||
|
|
}
|
||
|
|
}
|
||
|
|
{
|
||
|
|
GoogleRig none(false);
|
||
|
|
Fixture f(none.client);
|
||
|
|
auto del = f.client->request(Method::Delete, "/agent/optimize/operations?name=" + kOp);
|
||
|
|
check(del.status == 503 && contains(del.body, "google_not_configured"),
|
||
|
|
"delete operation: no credential is 503");
|
||
|
|
check(none.mock->send_count() == 0, "no network without a credential");
|
||
|
|
}
|
||
|
|
{
|
||
|
|
GoogleRig keyed;
|
||
|
|
Fixture f(keyed.client);
|
||
|
|
check(f.client->request(Method::Delete, "/agent/optimize/operations").status == 422,
|
||
|
|
"delete: missing name is 422");
|
||
|
|
check(f.client->request(Method::Delete, "/agent/optimize/operations?name=x").status == 422,
|
||
|
|
"delete: bad name is 422");
|
||
|
|
check(f.client->post("/agent/optimize/operations").status == 405, "post on the delete route is 405");
|
||
|
|
check(keyed.mock->send_count() == 0, "side effect: rejected before any upstream call");
|
||
|
|
}
|
||
|
|
return finish("agent/optimize/gaps");
|
||
|
|
}
|