Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

agama config load/store for "software" uses the HTTP API #1548

Merged
merged 8 commits into from
Aug 27, 2024

Conversation

mvidner
Copy link
Contributor

@mvidner mvidner commented Aug 20, 2024

Problem

Patterns part of the migration of the CLI from D-Bus API to HTTP API:

Solution

  • Added SoftwareHTTPClient
  • Kept (D-Bus) SoftwareClient because it serves as the backend for the above

Testing

Screenshots

No

with a new SoftwareHTTPClient.
Underneath, the web service still uses the D-Bus SoftwareClient
@coveralls
Copy link

coveralls commented Aug 20, 2024

Coverage Status

coverage: 71.354% (+0.04%) from 71.319%
when pulling 54d48ba on http-client-software
into 55fabd7 on master.

Note the `when.(...).body("{JSON object}")` part

where the JSON must match what the client sends,
otherwise the mock server will respond with a 404,
and the test will rightly fail with:
```
Error: BackendError(404, "{\"message\":\"Request did not match any route or mock\"}")
```

The problem is that if you compose that JSON according to your best understanding of the client but make a typo, you are still left with that unhelpful 404.

These 3 parts were all need to arrive at a working string:

1. Enable httpmock logging by calling `env_logger::init();` at the start of the test function.
2. Show the request, by enabling the logging at runtime, at the right level: (`test_setting_software` is a partial match on the test name).

```console
(cd rust; RUST_LOG=httpmock=debug cargo test test_setting_software)
```

If you don't like typing, the really important bits are these. httpmock will also log the more detailed Trace level but it does not get in the way
```console
RUST_LOG=httpmock cargo test
```

3. Unfortunately the request will be logged not as text but as an array of bytes shown numerically. [Process the output with this script to extract the text.][extract]

[extract]: https://gist.github.com/mvidner/0e22ea82abecb44b469841929e5ec279#file-httpmock_body-rb
by starting NetworkManager before agama-web-server which depends on it
@mvidner mvidner marked this pull request as ready for review August 27, 2024 08:35

impl SoftwareHTTPClient {
pub fn new() -> Result<Self, ServiceError> {
Ok(Self {
Copy link
Contributor

Choose a reason for hiding this comment

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

you can use here new_with_base like Ok(Self.new_with_base(BaseHTTPClient::new()?))

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I see your point... IMHO my way is still not enough duplication to need the indirection :)

}

pub async fn set_config(&self, config: &SoftwareConfig) -> Result<(), ServiceError> {
// FIXME: test how errors come out:
Copy link
Contributor

Choose a reason for hiding this comment

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

well, it can be improved by decoding body of error response and creating error from it, if it is also service error. I plan to do it, but other higher priorities come in the way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's what I thought too, but

  1. in the end the code seeing these errors does no decisions, just shows them to the user
  2. if we wanted to do some decisions, we would have to serialize them better than with Display/Debug

@mvidner mvidner merged commit d0459fc into master Aug 27, 2024
6 checks passed
@mvidner mvidner deleted the http-client-software branch August 27, 2024 09:10
@imobachgs imobachgs mentioned this pull request Sep 20, 2024
imobachgs added a commit that referenced this pull request Sep 20, 2024
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