From 7df6a2456e859cd2d4e711a0a7c8ae0a2b5b5f44 Mon Sep 17 00:00:00 2001 From: Matthew Johnson Date: Thu, 4 Jan 2018 14:53:00 -0800 Subject: [PATCH] Add more tests for manifest creation Add two more tests for CreateManifests. One to test that the state flag is being set correctly for state files and another to test that empty directories are correctly added to the manifest. Signed-off-by: Matthew Johnson --- swupd/create_manifests_test.go | 35 ++++++++++++++++++++++++++++++++++ swupd/helpers_test.go | 5 +++++ 2 files changed, 40 insertions(+) diff --git a/swupd/create_manifests_test.go b/swupd/create_manifests_test.go index 9d29ee3..7bed328 100644 --- a/swupd/create_manifests_test.go +++ b/swupd/create_manifests_test.go @@ -398,3 +398,38 @@ func TestCreateManifestIncludeVersionBump(t *testing.T) { mustNotExist(t, filepath.Join(testDir, "www/30/Manifest.test-bundle")) mustNotExist(t, filepath.Join(testDir, "www/30/Manifest.included2")) } + +func TestCreateManifestsState(t *testing.T) { + testDir := mustSetupTestDir(t, "state") + defer removeIfNoErrors(t, testDir) + mustInitStandardTest(t, testDir, "0", "10", []string{}) + mustGenFile(t, testDir, "10", "os-core", "var/lib/test", "test") + if err := CreateManifests(10, false, 1, testDir); err != nil { + t.Fatal(err) + } + + re := regexp.MustCompile("D\\.s\\.\t.*\t10\t/var/lib\n") + if fileContainsRe(filepath.Join(testDir, "www/10/Manifest.os-core"), re) == "" { + t.Errorf("%v not found in 10/Manifest.os-core", re.String()) + } + + re = regexp.MustCompile("F\\.s\\.\t.*\t10\t/var/lib/test\n") + if fileContainsRe(filepath.Join(testDir, "www/10/Manifest.os-core"), re) == "" { + t.Errorf("%v not found in 10/Manifest.os-core", re.String()) + } +} + +func TestCreateManifestsEmptyDir(t *testing.T) { + testDir := mustSetupTestDir(t, "emptydir") + defer removeIfNoErrors(t, testDir) + mustInitStandardTest(t, testDir, "0", "10", []string{}) + mustGenBundleDir(t, testDir, "10", "os-core", "emptydir") + if err := CreateManifests(10, false, 1, testDir); err != nil { + t.Fatal(err) + } + + re := regexp.MustCompile("D\\.\\.\\.\t.*\t10\t/emptydir\n") + if fileContainsRe(filepath.Join(testDir, "www/10/Manifest.os-core"), re) == "" { + t.Errorf("%v not found in 10/Manifest.os-core", re.String()) + } +} diff --git a/swupd/helpers_test.go b/swupd/helpers_test.go index 3b0c901..a6e3c54 100644 --- a/swupd/helpers_test.go +++ b/swupd/helpers_test.go @@ -89,6 +89,11 @@ func removeIfNoErrors(t *testing.T, testDir string) { } } +func mustGenBundleDir(t *testing.T, testDir, ver, bundle, dirName string) { + dirPath := filepath.Join(testDir, "image", ver, bundle, dirName) + mustMkdir(t, dirPath) +} + var serverINITemplate = template.Must(template.New("server.ini").Parse(` [Server] emptydir={{.testDir}}/empty/