Repository navigation
Make test_configure_auth_application_default runnable without ADC - #226
Conversation
The test uses `mock.proxy` so the real `Writer#get_auth_from_application_default` is invoked, which then calls `Google::Auth.get_application_default([scope])`. That call needs Application Default Credentials to be available on the test host — `gcloud auth application-default login` or equivalent — otherwise it raises `Google::Auth::InitializationError: Your credentials were not found`. The test guards this with `omit "depends on env vars" if ENV["CI"] == "true"`, so CI passes, but the test fails for any contributor running `rake test` locally without ADC configured. Stub the underlying `Google::Auth.get_application_default` call (mirroring how `test_configure_auth_json_key_as_string` stubs `ServiceAccountCredentials.make_creds`). `mock.proxy` still verifies that `Writer#get_auth_from_application_default` is called; the library-level ADC lookup is no longer required, so the test runs on any machine and the CI omit is no longer needed.
Watson1978
left a comment
There was a problem hiding this comment.
Thanks for fixing this. I confirmed the change on my machine.
On master, this test fails locally with Google::Auth::InitializationError when ADC is not configured, and CI only skips it. With this PR, it passes with CI=true and with CI unset, and the full suite passes too. The stub also checks the scope argument passed to Google::Auth.get_application_default, which the test did not do before.
I left one optional suggestion. It is not a blocker.
| def test_configure_auth_application_default | ||
| omit "This testcase depends on some environment variables." if ENV["CI"] == "true" | ||
| authorization = Object.new | ||
| stub(Google::Auth).get_application_default([API_SCOPE]) { authorization } |
There was a problem hiding this comment.
NIT: Could you change only stub to mock on this line? With stub, this test still passes if Writer#get_auth_from_application_default stops calling Google::Auth.get_application_default. mock expects that call once with [API_SCOPE], and test-unit-rr verifies it during test cleanup. I tried this change. It catches a missing call, and the full suite still passes on my machine.
| stub(Google::Auth).get_application_default([API_SCOPE]) { authorization } | |
| mock(Google::Auth).get_application_default([API_SCOPE]) { authorization } |
There was a problem hiding this comment.
changed it to mock and confirmed for myself that all the tests pass and that switching it to mock catches if it the mock isn't called. 👍
mock fails the test if Writer#get_auth_from_application_default stops calling Google::Auth.get_application_default with [API_SCOPE]. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QcykUPtommiA8Jdhn3CtFK
|
The failure of "Ruby 3.0 unit testing on windows-latest" is not caused by this PR. This PR only changes setup-ruby gets HTTP 404 when it downloads the MSYS2 build tools for Ruby 3.0: MSYS2 deprecated the mingw64 environment, so Updating |
7fb9384
into
fluent-plugins-nursery:master
Fixes #162.
Summary
test_configure_auth_application_defaultfails for any contributor runningbundle exec rake testlocally without Application Default Credentials configured (gcloud auth application-default loginor equivalent). This is the same failure reported in #162 (closed as not-reproducible in 2018), which has been silently present for any new contributor since then.It uses
mock.proxy(writer).get_auth_from_application_default { stub! }so the realWriter#get_auth_from_application_defaultis invoked — which in turn callsGoogle::Auth.get_application_default([scope]). Without ADC on the host, that raisesGoogle::Auth::InitializationError: Your credentials were not found(or, in older versions,RuntimeError: Could not load the default credentials).The existing
omit "This testcase depends on some environment variables." if ENV["CI"] == "true"guard (added some time after #162 was closed) keeps CI green, but the test is still broken for local contributors.Fix
Stub the underlying
Google::Auth.get_application_defaultcall. This mirrors howtest_configure_auth_json_key_as_stringalready stubsGoogle::Auth::ServiceAccountCredentials.make_creds:mock.proxystill verifies thatWriter#get_auth_from_application_defaultis called. The library-level ADC lookup is intercepted, so the test runs on any machine — which means the CI-only omit is no longer needed and is removed by this PR.If you'd prefer the omit kept in place as a belt-and-braces guard, happy to amend.
Notes