swupd: import full-run test

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>
This commit is contained in:
Caio Marcelo de Oliveira Filho
2018-02-05 13:38:13 -08:00
committed by Matthew Johnson
parent 0b9fe09af2
commit 4bd460ff2d
2 changed files with 71 additions and 2 deletions
+34 -2
View File
@@ -1,6 +1,7 @@
package swupd
import (
"archive/tar"
"fmt"
"io"
"os"
@@ -377,6 +378,31 @@ func mustValidateZeroPack(t *testing.T, manifestPath, packPath string) {
_ = tr.Close()
}()
mustHaveDir := func(name string) {
hdr, err := tr.Next()
if err == io.EOF {
t.Fatalf("invalid pack: required dir %s not found", name)
}
if err != nil {
t.Fatalf("error reading pack: %s", err)
}
if hdr.Name != name {
t.Fatalf("invalid pack: required dir %s not found", name)
}
if hdr.Typeflag != tar.TypeDir {
t.Fatalf("invalid pack: %s is of type %c instead of %c (directory)", name, hdr.Typeflag, tar.TypeDir)
}
var expectedMode int64 = 0700
if hdr.Mode != expectedMode {
t.Fatalf("invalid pack: wrong permissions %s for %s, expected %s", os.FileMode(hdr.Mode), name, os.FileMode(expectedMode))
}
}
// swupd-server expected these two to always exist in that order, but we could
// relax this restriction later if needed.
mustHaveDir("delta/")
mustHaveDir("staged/")
for {
hdr, err := tr.Next()
if err == io.EOF {
@@ -385,8 +411,14 @@ 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/" {
t.Fatalf("multiple entries of %s directory", hdr.Name)
}
// No delta file (or anything else other than staged/ files) is expected
// in a zeropack.
if !strings.HasPrefix(hdr.Name, "staged/") {
t.Fatalf("invalid entry %s in zero pack, no staged/ prefix", hdr.Name)
}
h, err := newHashFromTarHeader(hdr)
if err != nil {
+37
View File
@@ -74,3 +74,40 @@ func TestIncludeVersionBump(t *testing.T) {
checkIncludes(t, ts.parseManifest(30, "included"), "os-core", "included-nested")
checkFileInManifest(t, ts.parseManifest(30, "included-nested"), 30, "/foobarbaz")
}
// Imported from swupd-server/test/functional/full-run.
func TestFullRun(t *testing.T) {
ts := newTestSwupd(t, "full-run-")
defer ts.cleanup()
ts.Bundles = []string{"os-core", "test-bundle"}
ts.write("image/10/test-bundle/foo", "foo")
ts.createManifests(10)
ts.createFullfiles(10)
infoOsCore := ts.createPack("os-core", 0, 10, "")
mustValidateZeroPack(t, ts.path("www/10/Manifest.os-core"), ts.path("www/10/pack-os-core-from-0.tar"))
mustHaveDeltaCount(t, infoOsCore, 0)
// Empty file (bundle file), empty dir, os-release.
mustHaveFullfileCount(t, infoOsCore, 3)
infoTestBundle := ts.createPack("test-bundle", 0, 10, "")
mustValidateZeroPack(t, ts.path("www/10/Manifest.test-bundle"), ts.path("www/10/pack-test-bundle-from-0.tar"))
mustHaveDeltaCount(t, infoTestBundle, 0)
// Empty file (bundle file), "foo".
mustHaveFullfileCount(t, infoTestBundle, 2)
testBundle := ts.parseManifest(10, "test-bundle")
checkIncludes(t, testBundle, "os-core")
checkFileInManifest(t, testBundle, 10, "/usr/share/clear/bundles/test-bundle")
osCore := ts.parseManifest(10, "os-core")
checkIncludes(t, osCore)
checkFileInManifest(t, osCore, 10, "/usr")
checkFileInManifest(t, osCore, 10, "/usr/lib")
checkFileInManifest(t, osCore, 10, "/usr/share")
checkFileInManifest(t, osCore, 10, "/usr/share/clear")
checkFileInManifest(t, osCore, 10, "/usr/share/clear/bundles")
checkFileInManifest(t, osCore, 10, "/usr")
}