Files

37 lines
2.2 KiB
C++
Raw Permalink Normal View History

// Route: POST /google/ops/services (enable and disable are dry runs by default)
#include "support/GoogleRig.hpp"
using namespace molo::example::test;
int main() {
setenv("GOOGLE_CLOUD_PROJECT", "test-project", 1);
GoogleRig rig(false);
Fixture f(rig.client);
auto post = [&](const std::string& body) {
return f.client->post("/google/ops/services", body, "application/json");
};
auto dry = post("{\"action\":\"enable\",\"api\":\"iam.googleapis.com\"}");
check(dry.status == 200 && contains(dry.body, "\"executed\":false") &&
contains(dry.body, "projects/test-project/services/iam.googleapis.com:enable"),
"enable is a dry run on the env project");
auto off = post("{\"action\":\"disable\",\"api\":\"iam.googleapis.com\",\"project\":\"p2\"}");
check(off.status == 200 && contains(off.body, "\"executed\":false") &&
contains(off.body, "projects/p2/services/iam.googleapis.com:disable"),
"disable is a dry run");
check(post("{\"action\":\"enable\",\"api\":\"iam.googleapis.com\",\"confirm\":true}").status == 503,
"confirmed enable without credential is 503");
check(post("{\"action\":\"list\"}").status == 503, "list without credential is 503");
check(post("{\"action\":\"list\",\"state\":\"BOGUS\"}").status == 422, "bad state is 422");
check(post("{\"action\":\"get\"}").status == 422, "get without api is 422");
check(post("{\"action\":\"get\",\"api\":\"a/b\"}").status == 422, "slash api is 422");
check(post("{\"action\":\"batch_get\",\"apis\":[]}").status == 422, "empty batch is 422");
check(post("{\"action\":\"batch_get\",\"apis\":[1]}").status == 422, "non-string api is 422");
check(post("{\"action\":\"batch_get\",\"apis\":[\"run.googleapis.com\"]}").status == 503, "batch_get is 503");
check(post("{\"action\":\"nope\"}").status == 422, "unknown action is 422");
check(post("{}").status == 422, "missing action is 422");
check(post("{\"action\":\"list\",\"project\":\"a/b\"}").status == 422, "bad project is 422");
check(f.client->get("/google/ops/services").status == 405, "get is 405");
check(rig.mock->send_count() == 0, "nothing reached Google");
return finish("google/ops/services");
}