diff --git a/swupd/format_switch_test.go b/swupd/format_switch_test.go index e623511..e223646 100644 --- a/swupd/format_switch_test.go +++ b/swupd/format_switch_test.go @@ -5,23 +5,17 @@ import ( "testing" ) -// Format 25 should not support minversions, iterative manifests, or delta manifests. -// Support for these features was added in format 26. -func TestManifestFormats25to26(t *testing.T) { - ts := newTestSwupd(t, "format25to26") +// Minversion support added in format 26 +func TestFormats25to26Minversion(t *testing.T) { + ts := newTestSwupd(t, "format25to26minversion") defer ts.cleanup() ts.Bundles = []string{"test-bundle"} - contents := strings.Repeat("large", 1000) - if len(contents) < minimumSizeToMakeDeltaInBytes { - t.Fatal("test content size is invalid") - } - // format25 MoM should NOT have minversion in header, which is introduced // in format26. (It should also not have it because minversion is set to 0) ts.Format = 25 - ts.addFile(10, "test-bundle", "/foo", contents+"A") + ts.addFile(10, "test-bundle", "/foo", "content") ts.createManifests(10) expSubs := []string{ @@ -47,7 +41,7 @@ func TestManifestFormats25to26(t *testing.T) { // minversion now set to 20, but the MoM should still NOT have minversion // in header due to format25 being used ts.MinVersion = 20 - ts.addFile(20, "test-bundle", "/foo", contents+"B") + ts.addFile(20, "test-bundle", "/foo", "new content") ts.createManifests(20) expSubs = []string{ @@ -59,22 +53,12 @@ func TestManifestFormats25to26(t *testing.T) { "20\t/foo", } checkManifestContains(t, ts.Dir, "20", "test-bundle", expSubs...) - - // Iterative manifests should not have entries in the MoM or be generated - checkManifestNotContains(t, ts.Dir, "20", "MoM", "minversion:\t20", "I...\t") - ts.checkNotExists("www/20/Manifest.test-bundle.I.10") - ts.checkNotExists("www/20/os-core.I.10") - - // Delta manifests should not exist in format 25 - ts.mustHashFile("image/10/full/foo") - ts.mustHashFile("image/20/full/foo") - ts.createPack("test-bundle", 10, 20, ts.path("image")) - ts.checkNotExists("www/20/Manifest.test-bundle.D.10") + checkManifestNotContains(t, ts.Dir, "20", "MoM", "minversion:\t") // updated to format26, minversion still set to 20, so we should see // minversion header in the MoM ts.Format = 26 - ts.addFile(30, "test-bundle", "/foo", contents+"C") + ts.addFile(30, "test-bundle", "/foo", "even newer content") ts.createManifests(30) expSubs = []string{ "MANIFEST\t26", @@ -85,14 +69,79 @@ func TestManifestFormats25to26(t *testing.T) { } checkManifestContains(t, ts.Dir, "30", "test-bundle", expSubs...) checkManifestContains(t, ts.Dir, "30", "MoM", "minversion:\t20") +} - ts.addFile(40, "test-bundle", "/foo", contents+"D") +// Iterative manifest support added in format 26 +func TestFormats25to26IterativeManifest(t *testing.T) { + ts := newTestSwupd(t, "format25to26iterativeManifest") + defer ts.cleanup() + + ts.Bundles = []string{"test-bundle"} + + // Format 25 should not have iterative manifest support + ts.Format = 25 + ts.addFile(10, "test-bundle", "/foo", "content") + ts.createManifests(10) + + ts.addFile(20, "test-bundle", "/foo", "new content") + ts.createManifests(20) + checkManifestContains(t, ts.Dir, "20", "MoM", "MANIFEST\t25") + + // Iterative manifests should not have entries in the MoM or be generated + checkManifestNotContains(t, ts.Dir, "20", "MoM", "I...\t") + ts.checkNotExists("www/20/Manifest.test-bundle.I.10") + ts.checkNotExists("www/20/Manifest.os-core.I.10") + + // Update to format26 + ts.Format = 26 + ts.addFile(30, "test-bundle", "/foo", "even newer content") + ts.createManifests(30) + + ts.addFile(40, "test-bundle", "/foo", "more new content") ts.createManifests(40) + checkManifestContains(t, ts.Dir, "40", "MoM", "MANIFEST\t26") // Updates in format 26 should support iterative manifests checkManifestContains(t, ts.Dir, "40", "MoM", "\ttest-bundle.I.30", "\tos-core.I.30") ts.checkExists("www/40/Manifest.test-bundle.I.30") ts.checkExists("www/40/Manifest.os-core.I.30") +} + +// Delta manifest support added in format 26 +func TestFormats25to26DeltaManifest(t *testing.T) { + ts := newTestSwupd(t, "format25to26deltaManifest") + defer ts.cleanup() + + ts.Bundles = []string{"test-bundle"} + + contents := strings.Repeat("large", 1000) + if len(contents) < minimumSizeToMakeDeltaInBytes { + t.Fatal("test content size is invalid") + } + + // Format 25 should not have delta manifest support + ts.Format = 25 + ts.addFile(10, "test-bundle", "/foo", contents+"A") + ts.createManifests(10) + + ts.addFile(20, "test-bundle", "/foo", contents+"B") + ts.createManifests(20) + checkManifestContains(t, ts.Dir, "20", "MoM", "MANIFEST\t25") + + // Delta manifests should not exist + ts.mustHashFile("image/10/full/foo") + ts.mustHashFile("image/20/full/foo") + ts.createPack("test-bundle", 10, 20, ts.path("image")) + ts.checkNotExists("www/20/Manifest.test-bundle.D.10") + + // Update to format26 + ts.Format = 26 + ts.addFile(30, "test-bundle", "/foo", contents+"C") + ts.createManifests(30) + + ts.addFile(40, "test-bundle", "/foo", contents+"D") + ts.createManifests(40) + checkManifestContains(t, ts.Dir, "40", "MoM", "MANIFEST\t26") // Delta manifests should be created in format 26 ts.mustHashFile("image/30/full/foo")