// Routes: POST /google/cloudai/{video/annotate,documentai/*,speech/*,tts/*,operation,call} #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); const char* j = "application/json"; // video std::string v = "{\"inputUri\":\"gs://b/v.mp4\",\"features\":[\"LABEL_DETECTION\"]"; check(f.client->post("/google/cloudai/video/annotate", v + "}", j).status == 200, "video dry run"); check(f.client->post("/google/cloudai/video/annotate", v + ",\"confirm\":true}", j).status == 503, "video confirmed is 503"); check(f.client->post("/google/cloudai/video/annotate", "{\"inputUri\":\"gs://b/v\",\"features\":[\"X\"]}", j).status == 422, "bad feature"); check(f.client->post("/google/cloudai/video/annotate", "{}", j).status == 422, "features required"); // document ai std::string d = "{\"processorId\":\"abc\",\"gcsUri\":\"gs://b/d.pdf\",\"mimeType\":\"application/pdf\""; auto dd = f.client->post("/google/cloudai/documentai/process", d + "}", j); check(dd.status == 200 && contains(dd.body, "gcsDocument"), "process dry run"); check(f.client->post("/google/cloudai/documentai/process", d + ",\"confirm\":true}", j).status == 503, "process confirmed is 503"); auto inline_doc = f.client->post("/google/cloudai/documentai/process", "{\"processorId\":\"abc\",\"content\":\"" + std::string(1000, 'A') + "\",\"mimeType\":\"application/pdf\"}", j); check(inline_doc.status == 200 && contains(inline_doc.body, "1000 characters") && !contains(inline_doc.body, "AAAAAAAAAA"), "long content is not echoed"); check(f.client->post("/google/cloudai/documentai/process", "{\"processorId\":\"a/b\",\"gcsUri\":\"gs://b/d\",\"mimeType\":\"application/pdf\"}", j).status == 422, "bad processor id"); check(f.client->post("/google/cloudai/documentai/process", "{\"processorId\":\"a\",\"gcsUri\":\"gs://b/d\",\"mimeType\":\"x/y\"}", j).status == 422, "bad mime"); check(f.client->post("/google/cloudai/documentai/list", "{\"what\":\"processors\",\"location\":\"eu\"}", j).status == 503, "list is 503"); check(f.client->post("/google/cloudai/documentai/list", "{\"what\":\"versions\"}", j).status == 422, "versions need processorId"); // speech std::string s = "{\"languages\":[\"nl-NL\"],\"uri\":\"gs://b/a.wav\""; check(f.client->post("/google/cloudai/speech/recognize", s + "}", j).status == 200, "recognize dry run"); check(f.client->post("/google/cloudai/speech/recognize", s + ",\"confirm\":true}", j).status == 503, "recognize confirmed is 503"); check(f.client->post("/google/cloudai/speech/recognize", "{\"uri\":\"gs://b/a\"}", j).status == 422, "languages required"); check(f.client->post("/google/cloudai/speech/recognize", "{\"languages\":[\"nl\"],\"uri\":\"gs://b/a\",\"model\":\"Bad Model\"}", j).status == 422, "bad model"); check(f.client->post("/google/cloudai/speech/list", "{\"what\":\"recognizers\"}", j).status == 503, "speech list is 503"); // long audio std::string t = "{\"text\":\"Hello\",\"language\":\"en-US\",\"outputUri\":\"gs://b/o.wav\""; auto td = f.client->post("/google/cloudai/tts/long", t + "}", j); check(td.status == 200 && contains(td.body, "synthesizeLongAudio"), "long audio dry run"); check(f.client->post("/google/cloudai/tts/long", t + ",\"confirm\":true}", j).status == 503, "long audio confirmed is 503"); check(f.client->post("/google/cloudai/tts/long", "{\"text\":\"x\",\"language\":\"en-US\",\"outputUri\":\"o.wav\"}", j).status == 422, "bad outputUri"); check(f.client->post("/google/cloudai/tts/voices", "{}", j).status == 503, "voices is 503"); check(f.client->post("/google/cloudai/tts/voices", "{\"language\":\"n l\"}", j).status == 422, "bad language"); // operation check(f.client->post("/google/cloudai/operation", "{\"api\":\"video\",\"name\":\"projects/1/locations/us-east1/operations/2\"}", j).status == 503, "operation get is 503"); check(f.client->post("/google/cloudai/operation", "{\"api\":\"video\",\"name\":\"operations/2\"}", j).status == 422, "bad operation name"); check(f.client->post("/google/cloudai/operation", "{\"api\":\"other\",\"name\":\"x\"}", j).status == 422, "bad api"); // generic call check(f.client->post("/google/cloudai/call", "{\"rpc\":\"translate.projects.locations.glossaries.list\",\"name\":\"projects/p/locations/global\"}", j).status == 503, "GET row runs, 503"); auto cd = f.client->post("/google/cloudai/call", "{\"rpc\":\"translate.projects.locations.glossaries.delete\",\"name\":\"projects/p/locations/global/glossaries/g\"}", j); check(cd.status == 200 && contains(cd.body, "\"dry_run\":true") && contains(cd.body, "\"http\":\"DELETE\""), "DELETE row is a dry run"); check(f.client->post("/google/cloudai/call", "{\"rpc\":\"translate.projects.locations.glossaries.delete\",\"name\":\"projects/p/locations/global/glossaries/g\",\"confirm\":true}", j).status == 503, "confirmed DELETE is 503"); check(f.client->post("/google/cloudai/call", "{\"rpc\":\"nope\"}", j).status == 422, "unknown rpc"); check(f.client->post("/google/cloudai/call", "{\"rpc\":\"translate.projects.locations.translateText\",\"name\":\"projects/p/locations/global\",\"body\":{\"bogus\":1}}", j).status == 422, "unknown request field"); check(f.client->post("/google/cloudai/call", "{\"rpc\":\"translate.projects.locations.glossaries.list\",\"name\":\"projects/p\"}", j).status == 422, "name not matching the pattern"); check(f.client->post("/google/cloudai/call", "{\"rpc\":\"translate.projects.locations.glossaries.list\",\"name\":\"projects/p/locations/global\",\"query\":{\"bogus\":\"1\"}}", j).status == 422, "unknown query parameter"); check(f.client->get("/google/cloudai/call").status == 405, "get is 405"); check(rig.mock->send_count() == 0, "nothing reached Google"); return finish("google/cloudai/media"); }