From 59c21bf79a0b74abb084eddd20d7bd06de56fac8 Mon Sep 17 00:00:00 2001 From: Caio Marcelo de Oliveira Filho Date: Mon, 5 Feb 2018 17:53:39 -0800 Subject: [PATCH] swupd: import full-run-delta test Import original test from swupd-server. It performs checks when creating a new version shuffling some files between bundles and also create delta packs. The only difference from original is to not check for Manifest to be inside the packs anymore, as we are not packing them. Signed-off-by: Caio Marcelo de Oliveira Filho --- swupd/helpers_test.go | 15 +++++++++ swupd/swupd_test.go | 75 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/swupd/helpers_test.go b/swupd/helpers_test.go index 14f536a..08ca2db 100644 --- a/swupd/helpers_test.go +++ b/swupd/helpers_test.go @@ -354,6 +354,21 @@ func fileNotInManifest(t *testing.T, m *Manifest, name string) { } } +func fileDeletedInManifest(t *testing.T, m *Manifest, version uint32, name string) { + f := fileInManifest(t, m, version, name) + if f.Status != StatusDeleted { + t.Fatalf("manifest %s version %d has file %s marked as %q, but expected \"d\" (deleted)", m.Name, m.Header.Version, name, f.Status) + } + // TODO: Later on worth having a different helper function for handling delete/rename. + if f.Hash.String() != AllZeroHash { + t.Fatalf("manifest %s version %d has deleted file %s with hash %s, but expected %s", m.Name, m.Header.Version, f.Name, f.Hash, AllZeroHash) + + } + if f.Version != version { + t.Fatalf("manifest %s version %d has deleted file %s with version %d, but expected %d", m.Name, m.Header.Version, f.Name, f.Version, version) + } +} + func checkIncludes(t *testing.T, m *Manifest, includes ...string) { if len(m.Header.Includes) != len(includes) { t.Errorf("manifest %s in version %d has %d includes but expected %d", m.Name, m.Header.Version, len(m.Header.Includes), len(includes)) diff --git a/swupd/swupd_test.go b/swupd/swupd_test.go index 45c754b..53c7a7e 100644 --- a/swupd/swupd_test.go +++ b/swupd/swupd_test.go @@ -1,6 +1,9 @@ package swupd -import "testing" +import ( + "strings" + "testing" +) // Imported from swupd-server/test/functional/include-version-bump. func TestIncludeVersionBump(t *testing.T) { @@ -111,3 +114,73 @@ func TestFullRun(t *testing.T) { checkFileInManifest(t, osCore, 10, "/usr/share/clear/bundles") checkFileInManifest(t, osCore, 10, "/usr") } + +// Imported from swupd-server/test/functional/full-run-delta. +func TestFullRunDelta(t *testing.T) { + ts := newTestSwupd(t, "full-run-delta-") + defer ts.cleanup() + + content := strings.Repeat("CONTENT", 1000) + + // Version 10. + ts.Bundles = []string{"os-core", "test-bundle"} + ts.write("image/10/test-bundle/largefile", content) + ts.write("image/10/test-bundle/foo", "foo") + ts.write("image/10/test-bundle/foobarbaz", "foobarbaz") + ts.createManifests(10) + ts.createFullfiles(10) + + ts.createPack("os-core", 0, 10, ts.path("image")) + info := ts.createPack("test-bundle", 0, 10, ts.path("image")) + mustHaveFullfileCount(t, info, 4) // largefile, foo and foobarbaz and the test-bundle file. + + mustValidateZeroPack(t, ts.path("www/10/Manifest.os-core"), ts.path("www/10/pack-os-core-from-0.tar")) + mustValidateZeroPack(t, ts.path("www/10/Manifest.test-bundle"), ts.path("www/10/pack-test-bundle-from-0.tar")) + + testBundle10 := ts.parseManifest(10, "test-bundle") + checkIncludes(t, testBundle10, "os-core") + checkFileInManifest(t, testBundle10, 10, "/foo") + checkFileInManifest(t, testBundle10, 10, "/foobarbaz") + + // Version 20 adds new bundles and copy some files to them. + ts.Bundles = append(ts.Bundles, "included", "included-two", "included-nested") + ts.write("image/20/test-bundle/largefile", content+"delta") + ts.write("image/20/test-bundle/foo", "foo") + ts.write("image/20/included/foo", "foo") + ts.write("image/20/included-two/foo", "foo") + ts.write("image/20/included-two/foobar", "foobar") + ts.write("image/20/included-nested/foobarbaz", "foobarbaz") + ts.write("image/20/noship/test-bundle-includes", "included\nincluded-two") + ts.write("image/20/noship/included-includes", "included-nested") + + ts.createManifests(20) + ts.createFullfiles(20) + + ts.createPack("os-core", 0, 20, ts.path("image")) + info = ts.createPack("test-bundle", 0, 20, ts.path("image")) + mustHaveFullfileCount(t, info, 2) // largefile and the test-bundle file. + + mustValidateZeroPack(t, ts.path("www/20/Manifest.os-core"), ts.path("www/20/pack-os-core-from-0.tar")) + mustValidateZeroPack(t, ts.path("www/20/Manifest.test-bundle"), ts.path("www/20/pack-test-bundle-from-0.tar")) + + testBundle20 := ts.parseManifest(20, "test-bundle") + checkIncludes(t, testBundle20, "os-core", "included", "included-two") + fileNotInManifest(t, testBundle20, "/foobar") + fileDeletedInManifest(t, testBundle20, 20, "/foo") + fileDeletedInManifest(t, testBundle20, 20, "/foobarbaz") + + fileInManifest(t, ts.parseManifest(20, "included"), 20, "/foo") + fileInManifest(t, ts.parseManifest(20, "included-two"), 20, "/foo") + fileInManifest(t, ts.parseManifest(20, "included-two"), 20, "/foobar") + fileInManifest(t, ts.parseManifest(20, "included-nested"), 20, "/foobarbaz") + + // Create delta packs. + ts.createPack("os-core", 10, 20, ts.path("image")) + info = ts.createPack("test-bundle", 10, 20, ts.path("image")) + + mustHaveFullfileCount(t, info, 0) + mustHaveDeltaCount(t, info, 1) // largefile. + + // NOTE: original test checked whether the packs had the manifests inside. This is + // not done by new swupd since it seems the client doesn't take advantage of them. +}