Compute, Cloud Run, Functions, GKE, Build, Artifact Registry, IAM, IAM Credentials, Resource Manager, Service Usage, Logging, Monitoring, Scheduler, Tasks, Workflows, Eventarc, Billing, Asset, Org Policy. Generated call table checked against Discovery, validated plans, dry-run default for writes (enable/disable never live), /google/ops demo routes, live read-only probe. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
128 lines
5.5 KiB
C++
128 lines
5.5 KiB
C++
// Ops call table invariants. The table is generated from Discovery by
|
|
// src/google/ops/tools/gen_calls.py and checked against Discovery by
|
|
// tools/check_discovery.py; these tests pin the properties the code relies on.
|
|
#include <map>
|
|
#include <set>
|
|
#include <string>
|
|
|
|
#include "framework.h"
|
|
#include "clients/transports/mock_transport.h"
|
|
#include "google/errors.h"
|
|
#include "google/ops/calls.h"
|
|
#include "google/ops/ops.h"
|
|
|
|
using namespace molo::google;
|
|
using namespace molo::google::ops;
|
|
|
|
TEST(ops_calls, table_is_large_and_unique) {
|
|
ASSERT_TRUE(call_count() >= 400);
|
|
std::set<std::string> seen;
|
|
for (std::size_t i = 0; i < call_count(); ++i) {
|
|
const CallSpec& c = call_table()[i];
|
|
ASSERT_TRUE(seen.insert(c.rpc).second);
|
|
ASSERT_TRUE(find_call(c.rpc) == &c);
|
|
}
|
|
}
|
|
|
|
TEST(ops_calls, every_row_has_a_product_and_consistent_safety) {
|
|
for (std::size_t i = 0; i < call_count(); ++i) {
|
|
const CallSpec& c = call_table()[i];
|
|
product_named(c.product());
|
|
std::string http = c.http;
|
|
if (http == "DELETE") ASSERT_TRUE(c.safe() == Safety::kDestructive);
|
|
// A GET never changes state.
|
|
if (http == "GET") ASSERT_TRUE(c.safe() == Safety::kRead);
|
|
// Destructive rows are named delete / purge / batchDelete.
|
|
if (c.safe() == Safety::kDestructive) {
|
|
std::string rpc = c.rpc;
|
|
std::string verb = rpc.substr(rpc.rfind('.') + 1);
|
|
ASSERT_TRUE(verb.rfind("delete", 0) == 0 || verb == "batchDelete" || verb == "purge");
|
|
}
|
|
// Bodiless verbs declare no body fields.
|
|
if (http == "GET" || http == "DELETE") ASSERT_EQ(std::string(c.body_fields), "");
|
|
}
|
|
}
|
|
|
|
TEST(ops_calls, path_parameters_and_shapes) {
|
|
for (std::size_t i = 0; i < call_count(); ++i) {
|
|
const CallSpec& c = call_table()[i];
|
|
std::string path = c.path, shapes = c.path_shapes;
|
|
std::size_t params = 0;
|
|
for (std::size_t at = path.find('{'); at != std::string::npos; at = path.find('{', at + 1)) ++params;
|
|
std::size_t entries = shapes.empty() ? 0 : 1;
|
|
for (char ch : shapes) entries += ch == ' ' ? 1 : 0;
|
|
ASSERT_EQ(params, entries);
|
|
}
|
|
}
|
|
|
|
TEST(ops_calls, list_rows_name_their_items) {
|
|
std::size_t lists = 0;
|
|
for (std::size_t i = 0; i < call_count(); ++i) {
|
|
const CallSpec& c = call_table()[i];
|
|
if (c.is_list()) {
|
|
++lists;
|
|
ASSERT_TRUE(c.safe() == Safety::kRead);
|
|
}
|
|
}
|
|
ASSERT_TRUE(lists >= 100);
|
|
}
|
|
|
|
TEST(ops_calls, every_required_area_is_covered) {
|
|
const char* areas[] = {
|
|
"compute.instances.list", "run.projects.locations.services.list",
|
|
"cloudfunctions.projects.locations.functions.list", "container.projects.locations.clusters.list",
|
|
"cloudbuild.projects.locations.builds.list", "artifactregistry.projects.locations.repositories.list",
|
|
"iam.roles.list", "iam.projects.serviceAccounts.list", "iam.projects.serviceAccounts.keys.create",
|
|
"iam.projects.serviceAccounts.testIamPermissions", "iamcredentials.projects.serviceAccounts.signJwt",
|
|
"iamcredentials.projects.serviceAccounts.signBlob", "cloudresourcemanager.projects.get",
|
|
"serviceusage.services.enable", "serviceusage.services.disable", "serviceusage.services.list",
|
|
"serviceusage.services.batchGet", "logging.entries.list", "monitoring.projects.timeSeries.list",
|
|
"cloudscheduler.projects.locations.jobs.list", "cloudtasks.projects.locations.queues.list",
|
|
"workflows.projects.locations.workflows.list", "eventarc.projects.locations.triggers.list",
|
|
"cloudbilling.billingAccounts.list", "cloudasset.searchAllResources",
|
|
"orgpolicy.projects.policies.list"};
|
|
for (const char* rpc : areas) ASSERT_TRUE(find_call(rpc) != nullptr);
|
|
ASSERT_EQ(product_count(), 20u);
|
|
}
|
|
|
|
TEST(ops_calls, enable_and_disable_are_writes) {
|
|
ASSERT_TRUE(call_named("serviceusage.services.enable").safe() == Safety::kWrite);
|
|
ASSERT_TRUE(call_named("serviceusage.services.disable").safe() == Safety::kWrite);
|
|
ASSERT_TRUE(call_named("serviceusage.services.list").safe() == Safety::kRead);
|
|
// Signing and permission tests change nothing.
|
|
ASSERT_TRUE(call_named("iamcredentials.projects.serviceAccounts.signJwt").safe() == Safety::kRead);
|
|
ASSERT_TRUE(call_named("iam.projects.serviceAccounts.testIamPermissions").safe() == Safety::kRead);
|
|
ASSERT_TRUE(call_named("iam.projects.serviceAccounts.delete").safe() == Safety::kDestructive);
|
|
ASSERT_TRUE(call_named("cloudtasks.projects.locations.queues.purge").safe() == Safety::kDestructive);
|
|
}
|
|
|
|
TEST(ops_calls, endpoints_come_from_discovery) {
|
|
ASSERT_EQ(endpoint_of(product_named("run")).base_url, "https://run.googleapis.com");
|
|
ASSERT_EQ(endpoint_of(product_named("compute")).base_url,
|
|
"https://compute.googleapis.com/compute/v1");
|
|
ASSERT_EQ(operation_endpoint_of(product_named("serviceusage")).base_url,
|
|
"https://serviceusage.googleapis.com/v1");
|
|
ASSERT_THROW(product_named("nope"), GoogleError);
|
|
ASSERT_THROW(call_named("run.nope"), GoogleError);
|
|
}
|
|
|
|
TEST(ops_calls, no_em_dash_in_table) {
|
|
for (std::size_t i = 0; i < call_count(); ++i) {
|
|
std::string row = std::string(call_table()[i].rpc) + call_table()[i].path;
|
|
ASSERT_TRUE(row.find("\xE2\x80\x94") == std::string::npos);
|
|
}
|
|
}
|
|
|
|
TEST(ops_calls, every_product_object_owns_its_rows) {
|
|
Ops ops(std::make_shared<GoogleClient>(
|
|
std::make_unique<molo::clients::transports::MockTransport>(), nullptr));
|
|
std::size_t total = 0;
|
|
for (const OpsProduct* p : ops.all()) {
|
|
auto rpcs = p->rpcs();
|
|
ASSERT_TRUE(!rpcs.empty());
|
|
total += rpcs.size();
|
|
}
|
|
// Every row is reachable through exactly one product object.
|
|
ASSERT_EQ(total, call_count());
|
|
}
|