fix(clients): hermetic tests ignore .env.json.local unless MOLO_LIVE_NET is set
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -58,6 +58,9 @@ client, credentials, errors, or caps.
|
||||
APIs that refuse keys) use the same seam: `Credentials::bearer`; a
|
||||
`GOOGLE_ACCESS_TOKEN` (same lookup order) takes precedence over a key.
|
||||
Tokens expire after about an hour; refresh is the caller's job (gap).
|
||||
- Test runs set `MOLO_ENV_FILES=off`: config files are ignored so a developer's
|
||||
`.env.json.local` cannot change test outcomes. `MOLO_LIVE_NET=1` re-enables
|
||||
them for the opt-in live checks.
|
||||
- No key: `configured()` is false and every call throws `NotConfiguredError`
|
||||
(HTTP 503, status `NOT_CONFIGURED`) before any network traffic. Loud, not
|
||||
silent.
|
||||
|
||||
@@ -43,6 +43,11 @@ std::string from_json_file(const char* path, const char* name) {
|
||||
// secrets), then .env.json, both in the working directory.
|
||||
std::string Credentials::env(const char* name) {
|
||||
if (const char* v = std::getenv(name); v && *v) return v;
|
||||
// Test runs set MOLO_ENV_FILES=off so a developer's .env.json.local never
|
||||
// leaks into hermetic tests; opt-in live runs (MOLO_LIVE_NET) need it.
|
||||
const char* files = std::getenv("MOLO_ENV_FILES");
|
||||
if (files && std::string(files) == "off" && !std::getenv("MOLO_LIVE_NET"))
|
||||
return "";
|
||||
std::string local = from_json_file(".env.json.local", name);
|
||||
if (!local.empty()) return local;
|
||||
return from_json_file(".env.json", name);
|
||||
|
||||
@@ -48,7 +48,7 @@ $(GOOGLE_LIB): $(GOOGLE_OBJS)
|
||||
|
||||
# The clients test harness (framework.h plus main.cpp) is reused, not copied.
|
||||
google-test: $(GOOGLE_TEST_BIN)
|
||||
$(GOOGLE_TEST_BIN)
|
||||
MOLO_ENV_FILES=off $(GOOGLE_TEST_BIN)
|
||||
|
||||
$(GOOGLE_TEST_BIN): $(GOOGLE_OBJS) $(GOOGLE_TEST_SRCS) $(CLIENTS_LIB) $(OPERABILITY_LIB) $(ROOT)/tests/src/clients/main.cpp
|
||||
@mkdir -p $(dir $@)
|
||||
|
||||
Reference in New Issue
Block a user