Skip to content

Make test_configure_auth_application_default runnable without ADC - #226

Merged
Watson1978 merged 2 commits into
fluent-plugins-nursery:masterfrom
mixcloud:fix/test-configure-auth-application-default-without-adc
Nov 11, 2026
Merged

Watson1978 merged 2 commits into
fluent-plugins-nursery:masterfrom
mixcloud:fix/test-configure-auth-application-default-without-adc

Conversation

@ben-xo

@ben-xo ben-xo commented May 14, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #162.

Summary

test_configure_auth_application_default fails for any contributor running bundle exec rake test locally without Application Default Credentials configured (gcloud auth application-default login or 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 real Writer#get_auth_from_application_default is invoked — which in turn calls Google::Auth.get_application_default([scope]). Without ADC on the host, that raises Google::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_default call. This mirrors how test_configure_auth_json_key_as_string already stubs Google::Auth::ServiceAccountCredentials.make_creds:

authorization = Object.new
stub(Google::Auth).get_application_default([API_SCOPE]) { authorization }

mock.proxy still verifies that Writer#get_auth_from_application_default is 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

  • No production code changes — test-only.

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 Watson1978 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread test/plugin/test_out_bigquery_base.rb Outdated
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 }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
stub(Google::Auth).get_application_default([API_SCOPE]) { authorization }
mock(Google::Auth).get_application_default([API_SCOPE]) { authorization }

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@Watson1978

Copy link
Copy Markdown
Contributor

The failure of "Ruby 3.0 unit testing on windows-latest" is not caused by this PR. This PR only changes test/plugin/test_out_bigquery_base.rb, and the job fails in ruby/setup-ruby before any test runs.

setup-ruby gets HTTP 404 when it downloads the MSYS2 build tools for Ruby 3.0:

https://github.com/ruby/setup-msys2-gcc/releases/latest/download/msys2-mingw64-mingw-w64@r688-gcc@14-openssl@1.1.7z

MSYS2 deprecated the mingw64 environment, so ruby/setup-msys2-gcc froze its mingw64 builds on 2026-11-06. Its latest release no longer has this file. setup-ruby v1.338.0 downloads it from the frozen release instead. This repository pins setup-ruby v1.335.0, which still uses the latest URL.

Updating ruby/setup-ruby in .github/workflows/windows.yml to v1.338.0 or later should fix it. master has the same problem, so it needs a separate fix there.

@Watson1978
Watson1978 merged commit 7fb9384 into fluent-plugins-nursery:master Nov 11, 2026
23 of 26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rake test fails

2 participants