Skip to content

test(go): add unit test suites and CI test verification for quickstart and azure-auth - #9363

Merged
Vincent Biret (baywet) merged 9 commits into
microsoft:mainfrom
hardikkaurani:fix/go-quickstart-test-suite-and-ci
Nov 11, 2026
Merged

Vincent Biret (baywet) merged 9 commits into
microsoft:mainfrom
hardikkaurani:fix/go-quickstart-test-suite-and-ci

Conversation

@hardikkaurani

Copy link
Copy Markdown
Contributor

Summary

While reviewing the Go Get Started samples (get-started/quickstart/go and get-started/azure-auth/go), I noticed that unlike other SDK samples (.NET, Dart, Ruby, PHP), the Go samples currently had no unit test coverage, and the CI workflow (get-started.go.yml) only executed compilation and an un-mocked live run without running go test ./....

Additionally:

  • In get-started/azure-auth/go/getuser.go, authentication and request errors were logged with fmt.Printf without terminating execution, falling through to potential nil-pointer dereferences on *me.GetDisplayName().
  • The .gitignore files in both Go samples were missing standard Go build and test artifact exclusions (*.exe, binaries, *.test, coverage.out).
  • The go-version in get-started.go.yml was set to ^1.24, whereas go.mod across the repository specifies go 1.26.0.

Changes

  1. Quickstart Unit Tests (get-started/quickstart/go/main_test.go):

    • TestPostsClient_Initialization: Validates PostsClient instantiation and default base URL (https://jsonplaceholder.typicode.com).
    • TestPostsClient_ToGetRequestInformation: Validates GET method, URL template ({+baseurl}/posts{?title*,userId*}), and Accept: application/json header.
    • TestPostsClient_ToGetRequestInformation_WithQueryParameters: Validates mapping of title and userId query parameters into RequestInformation.
    • TestPostsClient_ToPostRequestInformation: Validates POST request information generation and payload serialization.
    • TestPostsClient_ByPostIdInteger & TestPostsClient_ByPostIdString: Validates GET, PATCH, and DELETE item request builders and path parameter presence without coupling to internal URL-encoded key strings.
    • TestPostModel_PropertiesAndDeserializers: Validates Post model getters, setters, additional data, and deserializer dictionary completeness.
  2. Azure Auth Unit Tests (get-started/azure-auth/go/getuser_test.go):

    • TestGraphApiClient_Initialization: Validates client creation and base URL (https://graph.microsoft.com/v1.0).
    • TestGraphApiClient_MeToGetRequestInformation: Validates client.Me().ToGetRequestInformation method, URL template ({+baseurl}/me), and Accept header.
  3. Sample Error Handling (get-started/azure-auth/go/getuser.go):

    • Replaced non-terminating error prints with log.Fatalf consistent with quickstart/go/main.go.
  4. CI Workflow Improvements (.github/workflows/get-started.go.yml):

    • Added Run Azure auth tests step (go test -v ./...) to build-azure.
    • Added Run quickstart tests step (go test -v ./...) to build-quickstart.
    • Aligned go-version with go.mod (^1.26).
  5. Build Configuration:

    • Added standard Go binary and test artifact exclusions to get-started/quickstart/go/.gitignore and get-started/azure-auth/go/.gitignore.

Verification

All builds and tests pass cleanly locally:

cd get-started/quickstart/go && go build -v ./... && go test -v ./...
cd get-started/azure-auth/go && go build -v ./... && go test -v ./...

@hardikkaurani
Hardik K (hardikkaurani) requested a review from a team as a code owner November 11, 2026 06:22
Copilot AI balanced review requested due to automatic review settings November 11, 2026 06:22

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@hardikkaurani

Copy link
Copy Markdown
Contributor Author

Hi Vincent Biret (@baywet) — following up on the recent testing improvements across the other quickstarts (like the Dart suite in #9313), I noticed our Go samples were still lacking unit test suites and CI test execution.

This PR adds:

  1. Offline unit test coverage for quickstart/go (PostsClient initialization, base URL defaults, request information generation for GET/POST with query parameters and payload serialization, and item operations across GET, PATCH, and DELETE without coupling assertions to URL-encoded key names).
  2. Model integrity checks for models.Post getters, setters, and deserializer mappings.
  3. Unit tests for azure-auth/go (GraphApiClient initialization and client.Me().ToGetRequestInformation request validation).
  4. Error handling fix in azure-auth/go/getuser.go so credential or request failures terminate with log.Fatalf instead of falling through to nil pointer dereferences.
  5. Added go test -v ./... steps to both jobs in get-started.go.yml and aligned the CI Go version (^1.26) with the repo's go.mod declaration (1.26.0).

All builds and tests run cleanly locally. Whenever you have a chance, I'd appreciate your review!

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are identified for the Go sample testing and CI changes.

No open issues 🎉

Review effort: Balanced

@baywet
Vincent Biret (baywet) merged commit e1366d5 into microsoft:main Nov 11, 2026
31 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.

3 participants