agama config load/store for "software" uses the HTTP API#1548
Merged
agama config load/store for "software" uses the HTTP API#1548
agama config load/store for "software" uses the HTTP API#1548Conversation
to be used by SoftwareHTTPClient
with a new SoftwareHTTPClient. Underneath, the web service still uses the D-Bus SoftwareClient
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
jreidinger
reviewed
Aug 27, 2024
|
|
||
| impl SoftwareHTTPClient { | ||
| pub fn new() -> Result<Self, ServiceError> { | ||
| Ok(Self { |
Contributor
There was a problem hiding this comment.
you can use here new_with_base like Ok(Self.new_with_base(BaseHTTPClient::new()?))
Contributor
Author
There was a problem hiding this comment.
I see your point... IMHO my way is still not enough duplication to need the indirection :)
jreidinger
reviewed
Aug 27, 2024
| } | ||
|
|
||
| pub async fn set_config(&self, config: &SoftwareConfig) -> Result<(), ServiceError> { | ||
| // FIXME: test how errors come out: |
Contributor
There was a problem hiding this comment.
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.
Contributor
Author
There was a problem hiding this comment.
That's what I thought too, but
- in the end the code seeing these errors does no decisions, just shows them to the user
- if we wanted to do some decisions, we would have to serialize them better than with
Display/Debug
jreidinger
approved these changes
Aug 27, 2024
Merged
imobachgs
added a commit
that referenced
this pull request
Sep 20, 2024
Prepare for releasing Agama 10· * #1263 * #1330 * #1407 * #1408 * #1410 * #1411 * #1412 * #1416 * #1417 * #1419 * #1420 * #1421 * #1422 * #1423 * #1424 * #1425 * #1428 * #1429 * #1430 * #1431 * #1432 * #1433 * #1436 * #1437 * #1438 * #1439 * #1440 * #1441 * #1443 * #1444 * #1445 * #1449 * #1450 * #1451 * #1452 * #1453 * #1454 * #1455 * #1456 * #1457 * #1459 * #1460 * #1462 * #1464 * #1465 * #1466 * #1467 * #1468 * #1469 * #1470 * #1471 * #1472 * #1473 * #1475 * #1476 * #1477 * #1478 * #1479 * #1480 * #1481 * #1482 * #1483 * #1484 * #1485 * #1486 * #1487 * #1488 * #1489 * #1491 * #1492 * #1493 * #1494 * #1496 * #1497 * #1498 * #1499 * #1500 * #1501 * #1502 * #1503 * #1504 * #1505 * #1506 * #1507 * #1508 * #1510 * #1511 * #1512 * #1513 * #1514 * #1515 * #1516 * #1517 * #1518 * #1519 * #1520 * #1522 * #1523 * #1524 * #1525 * #1526 * #1527 * #1528 * #1529 * #1530 * #1531 * #1532 * #1533 * #1534 * #1535 * #1536 * #1537 * #1540 * #1541 * #1543 * #1544 * #1545 * #1546 * #1547 * #1548 * #1549 * #1550 * #1552 * #1553 * #1554 * #1555 * #1556 * #1557 * #1558 * #1559 * #1560 * #1562 * #1563 * #1565 * #1566 * #1567 * #1568 * #1569 * #1570 * #1571 * #1572 * #1573 * #1574 * #1575 * #1576 * #1577 * #1578 * #1579 * #1580 * #1581 * #1583 * #1584 * #1585 * #1586 * #1587 * #1588 * #1589 * #1590 * #1591 * #1592 * #1593 * #1596 * #1597 * #1598 * #1600 * #1602 * #1605 * #1606 * #1607 * #1608 * #1610 * #1611 * #1612 * #1613 * #1614 * #1619 * #1620 * #1621
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Patterns part of the migration of the CLI from D-Bus API to HTTP API:
Solution
SoftwareHTTPClientSoftwareClientbecause it serves as the backend for the aboveTesting
/testing_using_container.shScreenshots
No