-
Notifications
You must be signed in to change notification settings - Fork 36
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
swupd: improve test infrastructure and import tests from swupd-server #136
Conversation
Imported another test. |
swupd/helpers_test.go
Outdated
func newTestSwupd(t *testing.T, prefix string) *testSwupd { | ||
fs := newTestFileSystem(t, prefix) | ||
defer func() { | ||
if t.Failed() { |
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.
Do you mean if !t.Failed()
? This looks like it is cleaning up only if the test failed.
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.
The code is correct, but due to similarity how defer cleanup is used elsewhere might be confusing. If when creating a testSwupd we have a failure, cleanup any existing directory. Otherwise let it live because the caller will call cleanup themselves.
I'll add a comment there.
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.
Note that currently fs.cleanup won't really cleanup (because it was a failure) but will still show the helpful message with the path of the temporary directory.
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, thanks.
commit 1: one comment |
commit 3: did you see https://github.com/clearlinux/mixer-tools/blob/master/swupd/create_manifests_test.go#L231 ? |
swupd/packs_test.go
Outdated
} | ||
} | ||
|
||
mustHaveDir("delta/") |
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.
These rely on order right? If I'm right, can you put a comment in?
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.
Done. Also mentioned I think we can relax this in the future. For now I think the validation function is fine as is.
@@ -385,8 +409,12 @@ func mustValidateZeroPack(t *testing.T, manifestPath, packPath string) { | |||
if err != nil { | |||
t.Fatalf("error reading pack: %s", err) | |||
} | |||
if hdr.Name == "staged/" || !strings.HasPrefix(hdr.Name, "staged/") { | |||
continue | |||
if hdr.Name == "staged/" || hdr.Name == "delta/" { |
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.
Another good place to put the comment that you've already encountered these.
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.
The error message talks about "multiple %s found", so I think we are covered with that plus the other two comments added.
swupd/packs_test.go
Outdated
t.Fatalf("multiple entries of %s directory", hdr.Name) | ||
} | ||
|
||
if !strings.HasPrefix(hdr.Name, "staged/") { |
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.
And a comment that delta/ shouldn't have anything in it for a zero pack?
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.
Done.
commit 4: great full run test, couple comment requests. |
commit 5: that test wasn't really testing much of anything before. Oversight. Good update. +1 |
swupd/create_manifests_test.go
Outdated
defer ts.cleanup() | ||
|
||
ts.Bundles = []string{"os-core", "test-bundle"} | ||
ts.Format = 3 |
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.
You don't seem to change this value again. Why 3? I recall it was 3 in the old server because Clear Linux was on format 3 when the tests were originally written, but I don't think it is relevant here.
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.
Yes, I was just keeping the test doing as much as possible the same as before -- I guessed it was an historical reason or something. Having some tests using different formats is a win, but I think we have those around already.
I'll remove format 3 from tests that don't really depend on that.
swupd/create_manifests_test.go
Outdated
|
||
// TODO: Check what is the right behavior and fix the test if needed. | ||
if false { | ||
fileDeletedInManifest(ts.parseManifest(30, "os-core"), 20, "/foo") |
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.
os-core should definitely have the deleted file still. This will fail of course because deletes are not being persisted properly (see #134, it includes a persistDeletes test)
swupd/create_manifests_test.go
Outdated
|
||
// TODO: Check what is the right behavior and fix the test if needed. | ||
if false { | ||
fileDeletedInManifest(ts.parseManifest(40, "os-core"), 20, "/foo") |
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 should not fail, but will in its current state for the reason listed above.
commit 6: please remove the |
I've missed that one, otherwise I'd written the extra tests in there, sorry about that. @matthewrsj If you like the direction test helpers in this PR took, I'll amend the commit to remove the existing version of the test. Otherwise I'll just remove this commit and later post a PR adding the extra checks to that test. |
Can you actually just replace the old test as part of this commit or do you think that is out-of-scope? The new test uses the new helpers, which I like. |
/me realizes that's what you suggested doing @cmarcelo, +1 please do. |
Problem of having tests failing is make the test suite less useful, I think the TODOs and skipping the test is fine in this case, since this PR is not pushing the fix for the issue at the same time. When the fix land, it can get rid of TODOs and skips. |
I'll update the TODOs to reflect that knowledge. |
I disagree. The whole point of tests is so that they fail. It is easy to forget about TODOs and skips once something is merged. If that means we merge failing tests now at least we know what is failing and what needs to be fixed. I see no usefulness in tests that should be failing but are passing instead. EDIT: It may not be pretty to see CI failing, but at least we know there is an issue. If that means we don't merge the tests until the fix lands, that is better than merging meaningless tests because we can see the failures in the PR tab. |
If you merge a failing test, the CI output becomes less useful, because every PR and every test execution from now on will be marked as fail. Unless you verify each time: "hey, it's failing because the known failures A, B, C, so its fine", you might let some other failure to creep in. That manual verification is the opposite of what we want to achieve with the CI marking the PR as "checked". Are those skipped tests useful? They are a better version of the "// TODO: Hey, we should be persisting deletes here.", because they come with the exact code that is expected to be working. |
So verify every time. I think for minor tests what you say makes sense. This is a breaking issue though. The updates do not work over several versions until it is fixed. It should be advertised that the bug exists. Painful, but better than relying on memory that the TODO exists.
Sure, but I have an actual test in #134 to test for this This is all philosophical. I have a fix for the bug that I'll be pushing to a new PR in the next few minutes. |
Great! So we have a non-problem :-) |
Updated PR addressing comments. |
In the same spirit of testFileSystem struct. It also embeds the testFileSystem, so only one needs to be used in a test. Note that cleanup function will not delete the temporary directory if the test fails, to allow inspection (it also prints the directory name). Two tests were modified to illustrate how it should be used, one that was already using fs and another that wasn't. Signed-off-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Import test from original swupd-server. It checks whether contentsize is adding (and not adding) values correctly. At the moment directories are getting accounted in contentsize (should they), so use an empty bundle to get a baseline. So I checks independent of that factor. Also avoided checking the exact figure for os-core and full, and only do check the size increase between two versions for those. It might make sense to have a separate test that verify the contents of os-core match what is desired, but seemed out of scope of this one. Signed-off-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Import test from original swupd-server. It checks direct includes cause a version bump, and indirect ones don't. This test was already partially present, the new version adds in more checks to cover everything was being checked by the original tests and some more (e.g. validating contents of the packs). Signed-off-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
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.
Would have liked a couple more comments around how the zero pack scanning is done (expects alphabetical order, delta directory should not have any children), but that was optional, so +1.
Argh. Read but missed those when doing the second pass. |
Import test from original swupd-server. It performs basic checks of a complete execution for a new version: creating fullfiles and a zeropack. Incremented mustValidateZeroPack to check for presence of staged/ and delta/ and their properties. Signed-off-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Update the test so a smaller format is used when creating the next version, and verify that it fails. Signed-off-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Import test from original swupd-server. It checks if deleted files are correctly marked, taking includes into account. I've created some new checks based on swupd-server output. Signed-off-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
+1 again, thanks for adding the comments. |
Add testSwupd, in the same spirit of testFileSystem, to make tests less noisy.
Convert two tests to use it, to give some context for reviewing it.
Also import new tests from swupd-server.
Related to #138.