-
Notifications
You must be signed in to change notification settings - Fork 582
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
tests: use gojq - part 1 #14686
tests: use gojq - part 1 #14686
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #14686 +/- ##
==========================================
+ Coverage 78.95% 79.03% +0.07%
==========================================
Files 1084 1087 +3
Lines 146638 147628 +990
==========================================
+ Hits 115773 116672 +899
- Misses 23667 23728 +61
- Partials 7198 7228 +30
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
662aad6
to
08eab5a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First pass mostly looks good. I left a few questions about things that seemed like they could be broken out to another polar quest later.
# - with --yaml-input, can parse YAML | ||
GOBIN=$PROJECT_PATH/tests/bin \ | ||
CGO_ENABLED=0 \ | ||
go install github.com/itchyny/gojq/cmd/[email protected] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might consider just pulling one of the pre-built artefacts instead:
- https://github.com/itchyny/gojq/releases/download/v0.12.16/gojq_v0.12.16_linux_amd64.tar.gz
- https://github.com/itchyny/gojq/releases/download/v0.12.16/gojq_v0.12.16_linux_arm64.tar.gz
The build could be only done on arch mismatch.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are those built with CGO disabled?
snap ack "$TESTSLIB/assertions/developer1.account" | ||
snap ack "$TESTSLIB/assertions/developer1.account-key" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How is this related?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it never worked, but store-state was running without -e, so it failed quietly on https://github.com/canonical/snapd/pull/14686/files/08eab5ab589736cc661f00cffec08f72bcf1f0a7#diff-234265efe637e5730e201767212cce6ce6f4f5fea39bfb026a01913fa281afccL128
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I cherry picked along with store-state fixes into #14725
|
||
execute: | | ||
inspect_connection() { | ||
CONN="$1" | ||
# shellcheck disable=SC2002 | ||
cat /var/lib/snapd/state.json | jq --arg CONN "$CONN" -r '.data["conns"] | has($CONN)' | ||
# shellcheck disable=SC2002,SC2016 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is 2016?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
https://www.shellcheck.net/wiki/SC2016 I have no clue why it wasn't picked up before due to -r '... | has ($CONN)'
@@ -1,6 +1,7 @@ | |||
name: SNAPNAME | |||
summary: generic snap | |||
version: '1.0' | |||
base: core22 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we add this in the other pass later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer to avoid pulling in core because it masked bugs and wrong assumptions in the tests.
tests/main/store-state/task.yaml
Outdated
@@ -40,6 +29,10 @@ execute: | | |||
snap info core | MATCH "store-url:.*https://snapcraft.io" | |||
fi | |||
|
|||
# install dependecies before switching to fake store |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems related to the base change, but I don't really understand the significance. Can we add this in a second pass later?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not really, fake store does not forward install requests to the real store. The test snap installed here had no base, hence defaulted to 'core'. We installed jq & remarshal both of which pulled in 'core'. Since the install happened before switching over to fake store, it all worked by accident as the dependencies happened to be satisfied. Without jq or remarshal nothing pulls in the dependencies. That's why the snap's base was switched to core22 too, just to avoid pulling in core.
08eab5a
to
2047373
Compare
e781775
to
fbe5e86
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two comments:
Let's try to separate changes to bases to another PR so that it is clear they are not a factor here. Use core if you have to have something.
The store endpoint for find is sometimes throttled, perhaps we can use info instead?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I think I spotted a few typos, but otherwise looks good.
# slurp our two json files together into one json document, then convert | ||
# back to yaml and write out to the snap.yaml in the unpacked gadget snap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# slurp our two json files together into one json document, then convert | |
# back to yaml and write out to the snap.yaml in the unpacked gadget snap | |
# slurp our two yaml files together into one yaml document, then write | |
# out to the snap.yaml in the unpacked gadget snap |
# back to yaml and write out to the snap.yaml in the unpacked gadget snap | ||
jq -s '.[0] * .[1]' <(cat snap-yaml-extras.json) <(cat pc-gadget/meta/snap.json) | json2yaml | tee pc-gadget/meta/snap.yaml | ||
gojq -s --yaml-input --yaml-output '.[0] * .[1]' <(cat snap-yaml-extras.json) <(cat pc-gadget/meta/snap.json) | \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gojq -s --yaml-input --yaml-output '.[0] * .[1]' <(cat snap-yaml-extras.json) <(cat pc-gadget/meta/snap.json) | \ | |
gojq -s --yaml-input --yaml-output '.[0] * .[1]' <(cat snap-yaml-extras.yaml) <(cat pc-gadget/meta/snap.yaml) | \ |
# slurp our two json files together into one json document, then convert | ||
# back to yaml and write out to the snap.yaml in the unpacked gadget snap |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# slurp our two json files together into one json document, then convert | |
# back to yaml and write out to the snap.yaml in the unpacked gadget snap | |
# slurp our two yaml files together into one taml document, then write | |
# out to the snap.yaml in the unpacked gadget snap |
fbe5e86
to
d970c4b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work
d970c4b
to
fd699d5
Compare
I've rebased the branch on top of #14725 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, thanks!
fd699d5
to
16c94fa
Compare
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
… use gojq Signed-off-by: Maciej Borzecki <[email protected]>
…a-hook: use gojq Signed-off-by: Maciej Borzecki <[email protected]>
…nder tests/bin Since gojq may be running on a different system, make sure to build it statically. Also place the binary under $PROJECT_PATH/tests/bin which is automaticall added to $PATH. Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
Signed-off-by: Maciej Borzecki <[email protected]>
…k-hack: use gojq Signed-off-by: Maciej Borzecki <[email protected]>
…save-via-hook: use gojq Signed-off-by: Maciej Borzecki <[email protected]>
…k-hack: use gojq Signed-off-by: Maciej Borzecki <[email protected]>
…save-via-hook: use gojq Signed-off-by: Maciej Borzecki <[email protected]>
6ff0ed3
to
2706405
Compare
Failures:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me.
Thank you for pushing this forward.
This reverts commit ede0457.
* master: (44 commits) wrappers: do not reload activation units (canonical#14724) gadget/install: support for no{exec,dev,suid} mount flags interfaces/builtin/mount_control: add support for nfs mounts (canonical#14694) tests: use gojq - part 1 (canonical#14686) interfaces/desktop-legacy: allow DBus access to com.canonical.dbusmenu interfaces/builtin/fwupd.go: allow access to nvmem for thunderbolt plugin tests: removing uc16 executions (canonical#14575) tests: Added arm github runner to build snapd (canonical#14504) tests: no need to run spread when there are not tests matching the filter (canonical#14728) tests/lib/tools/store-state: exit on errors, update relevant tests (canonical#14725) tests: udpate the github workflow to run tests suggested by spread-filter tool (canonical#14519) testtime: add mockable timers for use in tests (canonical#14672) interface/screen_inhibit_control: Improve screen inhibit control for use on core (canonical#14134) tests: use images with 20G disk in openstack (canonical#14720) i/builtin: allow @ in custom-device filepaths (canonical#14651) tests: refactor test-snapd-desktop-layout-with-content tests: fix broken app definition tests: capitalize sentences in comments tests: wrap very long shell line tests: fix raciness in async startup and sync install ...
https://github.com/itchyny/gojq is almost-compatible replacement for jq, with additional features such as native support for YAML input and output.
Attempt to switch the tests to use gojq instead of jq. Where appropriate drop use
remarshal
, since YAML support is built in.Related: SNAPDENG-33306