canonical / canonical/inference-snaps

fix flaky tests: TestSnapInfo and TestGetComponents

Open
#352 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

cli
Dominant language
No language data
Stars
50
Forks
6
Avg merge
1d 20h
Merged PRs (30d)
7

Description

`TestSnapInfo` and `TestGetComponents` in [snap_store_test.go](https://github.com/canonical/inference-snaps-cli/blob/main/pkg/snap_store/snap_store_test.go) make real HTTP calls to `api.snapcraft.io`. They are flaky, since that server can (and sometimes does) return non 200 responses due to all kinds of network issues (e.g. check [this](https://github.com/canonical/inference-snaps-cli/actions/runs/34486248370/job/102901160441#step:4:3751) CI run).

Proposal
- Rewrite tests setting up `httptest.NewServer` to serve JSON fixtures for `/v2/snaps/info/` and `/v2/snaps/refresh`. Then the client should hook up to that mock server for requests
- ideally also add a case for an error response to verify error handling

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in pkg/snap_store/snap_store_test.go with TestSnapInfo and TestGetComponents, then inspect how the client configures requests. Run those tests before changing them; use the issue's httptest.Server proposal and JSON fixtures for /v2/snaps/info/ and /v2/snaps/refresh, including an error response case, and confirm the tests no longer call api.snapcraft.io.

Written by the indexing model from the issue text.

Assessment

Domain
testing
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
78/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.