Skip to content

fix(go): add unit test suites, error handling, and CI workflow for Go samples - #9383

Open
Hardik K (hardikkaurani) wants to merge 8 commits into
microsoft:mainfrom
hardikkaurani:fix/go-samples-test-suites-and-ci
Open

Hardik K (hardikkaurani) wants to merge 8 commits into
microsoft:mainfrom
hardikkaurani:fix/go-samples-test-suites-and-ci

Conversation

@hardikkaurani

Copy link
Copy Markdown
Contributor

Summary

This PR improves code quality, test coverage, and CI automation across the Go sample clients (petstore/go, msgraph-mail/go, and sample-api/clients/go):

  1. petstore/go:

    • Replaced Azure Identity device-code auth provider with AnonymousAuthenticationProvider{} (Swagger Petstore endpoints do not require authentication).
    • Replaced non-terminating error prints with log.Fatalf to prevent downstream execution on failure.
    • Added nil checks on pet response names.
    • Added comprehensive unit test suite covering client initialization, request builders (Pet, FindByStatus, StoreInventory), and models (Pet, Order).
    • Cleaned up unused transitive dependencies via go mod tidy.
  2. msgraph-mail/go:

    • Replaced non-terminating error logging on credential creation with log.Fatalf to prevent execution with invalid/uninitialized credentials.
    • Added nil checks before dereferencing message subjects.
    • Added comprehensive unit test suite covering client initialization, request builders (Messages, MailFolders), query parameters, and models (Message, MailFolder).
  3. sample-api/clients/go:

    • Corrected misleading comment referencing Microsoft Graph instead of the ToDo API allowed hosts.
    • Added comprehensive unit test suite covering client initialization, request builders (ToDoItems, ByIdGuid), query parameters, and models (ToDoItem, ToDoItemUpdate, ProblemDetails).
  4. Repository Hygiene & CI Automation:

    • Added .gitignore files to petstore/go, msgraph-mail/go, and sample-api/clients/go/src to avoid committing local build and test artifacts.
    • Added .github/workflows/go-samples.yml workflow to build and test all three Go sample applications in GitHub Actions.

Testing

All test suites were executed and pass locally:

  • petstore/go: 7 unit tests passed
  • msgraph-mail/go: 7 unit tests passed
  • sample-api/clients/go/src: 8 unit tests passed

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

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

Hardik K (hardikkaurani) commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor Author

Hi Vincent Biret (@baywet),

While reviewing the Go samples across the repository, I noticed a few areas for improvement and missing test coverage across petstore/go, msgraph-mail/go, and sample-api/clients/go:

  1. Authentication & Error Handling

    • petstore/go/app.go: Replaced the Azure Identity / Device Code authentication setup with AnonymousAuthenticationProvider{} since the Petstore OpenAPI specification does not require authentication. Also added a nil check before dereferencing pet names.
    • msgraph-mail/go/app.go: Replaced non-terminating error prints with log.Fatalf to prevent execution with uninitialized credentials, and added nil checks before accessing message subjects.
    • sample-api/clients/go/src/main.go: Corrected the allowed hosts comment, which incorrectly referenced Microsoft Graph instead of the ToDo API.
  2. Unit Test Coverage

    • Added dedicated test suites for all three Go samples, covering ApiClient initialization, request builders, query parameters, and model properties through app_test.go and main_test.go.
  3. Repository Hygiene & CI

    • Added standard Go .gitignore files to exclude local artifacts.
    • Added .github/workflows/go-samples.yml to automatically build and run the test suites for all three Go samples on pushes and pull requests.

All tests pass locally across the three directories.

Whenever you have a moment, I'd appreciate your review and feedback. Thank you!

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.

2 participants