Closed Micah-Kolide closed 5 months ago
Not sure why but it looks like my tests aren't returning data? When I tested this I ran go make test
and all was well.
@Micah-Kolide I think maybe it's that UID 1001 and 1002 aren't available on the CI runner but are on the machine you're testing on? When I check out your branch locally and run the tests, I run into an error with just test_data/example.output
because of unknown userid 1002
.
Doesn't seem the uids were the ci issue, but if it was an issue locally, then hopefully setting all tests to 1000 uid will be good enough to fix that.
--- FAIL: TestQueries (0.00s)
--- FAIL: TestQueries/test_data/empty.output (0.00s)
upgradeable_test.go:59:
Error Trace: /home/runner/work/launcher/launcher/ee/tables/nix_env/upgradeable/upgradeable_test.go:59
Error: Not equal:
expected: 1
actual : 0
Test: TestQueries/test_data/empty.output
--- FAIL: TestQueries/test_data/example.output (0.00s)
upgradeable_test.go:59:
Error Trace: /home/runner/work/launcher/launcher/ee/tables/nix_env/upgradeable/upgradeable_test.go:59
Error: Not equal:
expected: 18
actual : 0
Test: TestQueries/test_data/example.output
FAIL
coverage: 42.0% of statements
FAIL github.com/kolide/launcher/ee/tables/nix_env/upgradeable 0.013s
I'm not sure why the actual data is nil.
Doesn't seem the uids were the ci issue, but if it was an issue locally, then hopefully setting all tests to 1000 uid will be good enough to fix that.
--- FAIL: TestQueries (0.00s) --- FAIL: TestQueries/test_data/empty.output (0.00s) upgradeable_test.go:59: Error Trace: /home/runner/work/launcher/launcher/ee/tables/nix_env/upgradeable/upgradeable_test.go:59 Error: Not equal: expected: 1 actual : 0 Test: TestQueries/test_data/empty.output --- FAIL: TestQueries/test_data/example.output (0.00s) upgradeable_test.go:59: Error Trace: /home/runner/work/launcher/launcher/ee/tables/nix_env/upgradeable/upgradeable_test.go:59 Error: Not equal: expected: 18 actual : 0 Test: TestQueries/test_data/example.output FAIL coverage: 42.0% of statements FAIL github.com/kolide/launcher/ee/tables/nix_env/upgradeable 0.013s
I'm not sure why the actual data is nil.
Might just try just getting user.Current
at beginning of test and using that UID, may be root, but it should still work I think
@Micah-Kolide You're right -- I checked in a separate branch (https://github.com/kolide/launcher/actions/runs/7887606195/job/21523236389?pr=1597, List users ubuntu
job) and UIDs 1000 and 1001 exist.
It looks like it's this (threw more troubleshooting into that other branch to get the errors printed -- you can see here https://github.com/kolide/launcher/actions/runs/7887656985/job/21523401135?pr=1597, Test output
job)
failure querying user installed packages runAsUser nix-env command as user 1000: current user 1001 is not root and can't start process for other user 1000
I imagine we've handled this before in tests -- off the top of my head, maybe the gsettings
table has a good example for how to address this issue in tests or how to refactor to avoid it altogether?
Running
nix-env
can only return the current user's installed packages unless first you runnix-env -S <path_to_profile>
(this is also finicky as there can be a recursion error at certain profile locations)Thus I've wrapped the
nix-env
command withrunAsUser
to hopefully get the correct installed packages for an inputuid
.nix-env
is symlinked to a ton of places, but the most reliable seems to be/run/current-system/sw/bin/nix-env
./nix/var/nix/profiles/default/bin/nix-env
seems to only work for macOS.I'm going to add test data as well, but I wanted to get this up first.