Skip to content

test(providers/azure): make IsConfigured guards deterministic - #1468

Merged
cristim merged 1 commit into
mainfrom
chore/1465-azure-test-guards
Jul 20, 2026
Merged

test(providers/azure): make IsConfigured guards deterministic#1468
cristim merged 1 commit into
mainfrom
chore/1465-azure-test-guards

Conversation

@cristim

@cristim cristim commented Jul 19, 2026

Copy link
Copy Markdown
Member

Closes #1465

Summary

  • providers/azure/provider_test.go had three tests (TestAzureProvider_GetCredentials_NotConfigured, TestAzureProvider_GetServiceClient_NotConfigured, TestAzureProvider_GetRecommendationsClient_NotConfigured) that wrapped their assertions in if !p.IsConfigured() { ... } on a bare &AzureProvider{}.
  • With no credProvider injected, IsConfigured() fell through to the real realCredentialProvider{}.NewDefaultAzureCredential(). Construction succeeds on virtually any machine, so the guarded "not configured" assertions silently never ran, and the pattern normalized real-credential construction in tests.
  • Each test now injects the existing mockCredentialProvider configured to fail (SetCredentialProvider), asserts IsConfigured() is false unconditionally, and runs the negative-path assertion unconditionally instead of behind an if.
  • Grepped the file for other IsConfigured() guards or hazardous bare &AzureProvider{} constructions; no other instances found. The remaining bare &AzureProvider{} uses either don't touch IsConfigured()/credentials (Name(), DisplayName(), GetDefaultRegion(), GetSupportedServices()) or already inject a mock credential provider immediately after construction.

Test plan

  • gofmt -l . clean (from providers/azure/)
  • go vet ./... clean (from providers/azure/)
  • go test ./... -count=1 green, 710 tests passed across 14 packages (from providers/azure/)

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Tests
    • Improved Azure provider tests to reliably verify behavior when credentials are unavailable.
    • Added explicit checks that the provider reports itself as unconfigured and returns the expected error.

…1465)

The three affected tests wrapped assertions in `if !p.IsConfigured()`
around a bare `&AzureProvider{}`. With no credProvider injected,
IsConfigured() fell through to the real DefaultAzureCredential lookup,
which succeeds on virtually any machine, so the guarded negative-path
assertions silently never ran.

Inject the existing mockCredentialProvider configured to fail so
IsConfigured() deterministically returns false, and assert
unconditionally instead of behind an if-guard.
@cristim cristim added triaged Item has been triaged priority/p3 Polish / idea / may never ship severity/low Minor harm urgency/eventually No deadline impact/internal Team-internal only effort/xs Trivial / one-liner type/chore Maintenance / non-user-visible labels Jul 19, 2026
@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 23262b86-cdee-4654-abd6-90802b3075b3

📥 Commits

Reviewing files that changed from the base of the PR and between c848a07 and 5fc08c3.

📒 Files selected for processing (1)
  • providers/azure/provider_test.go

📝 Walkthrough

Walkthrough

Three AzureProvider tests now inject failing credential-provider mocks, explicitly assert the provider is unconfigured, and unconditionally verify the expected errors from credential and client retrieval methods.

Changes

Azure provider test determinism

Layer / File(s) Summary
Not-configured error validation
providers/azure/provider_test.go
The credentials, service client, and recommendations client tests use failing credential providers, assert IsConfigured() is false, and verify the expected not-configured errors without conditional guards.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Possibly related PRs

  • LeanerCloud/CUDly#591: Updates the same Azure provider tests to use explicit failing credential mocks for deterministic not-configured error validation.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately describes the Azure test change to make IsConfigured guards deterministic.
Linked Issues check ✅ Passed The PR injects a failing mockCredentialProvider in the three guarded Azure tests and runs negative-path assertions unconditionally, matching #1465.
Out of Scope Changes check ✅ Passed The changes stay within the Azure provider test fix and do not introduce unrelated code or public API changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/1465-azure-test-guards

Comment @coderabbitai help to get the list of available commands.

@cristim

cristim commented Jul 19, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@cristim

cristim commented Jul 20, 2026

Copy link
Copy Markdown
Member Author

@coderabbitai full review

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
Contributor
✅ Action performed

Full review finished.

@cristim
cristim merged commit 54f49d6 into main Jul 20, 2026
19 checks passed
@cristim
cristim deleted the chore/1465-azure-test-guards branch July 27, 2026 11:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

effort/xs Trivial / one-liner impact/internal Team-internal only priority/p3 Polish / idea / may never ship severity/low Minor harm triaged Item has been triaged type/chore Maintenance / non-user-visible urgency/eventually No deadline

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore(providers/azure): replace silent IsConfigured() test guards with injected fake credential provider

1 participant