]> xenbits.xensource.com Git - people/gdunlap/xsatool.git/commitdiff
Testing: Introduce 'system' test
authorGeorge Dunlap <george.dunlap@citrix.com>
Wed, 10 May 2017 16:09:48 +0000 (17:09 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Wed, 10 May 2017 16:10:38 +0000 (17:10 +0100)
To begin with, just clone repos and begin to set them up in a specific
state, so that we can test operations.

To make testing iteration faster, set FullClone == false.  After test
development is done, this should be set to "true" to make the cloning
continues to work.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
system_test.go [new file with mode: 0644]

diff --git a/system_test.go b/system_test.go
new file mode 100644 (file)
index 0000000..94a1449
--- /dev/null
@@ -0,0 +1,140 @@
+package main
+
+import (
+       "fmt"
+       "os"
+       "testing"
+)
+
+// Should we always do a new full clone (slow) or use a previous clone
+// if it exists (and leave clones for future callers)?
+var FullClone = false
+
+// Set up the repo in a known state.
+func InitRepo(t *testing.T) bool {
+       callRepoInit := true
+
+       if FullClone {
+               // Make temporary directory and cd to it
+               // rm -rf tmp
+               if err := os.RemoveAll("tmp"); err != nil {
+                       t.Errorf("Removing temporary path: %v", err)
+                       return false
+               }
+       } else {
+               // Check to see if the directory exists
+               _, err := os.Stat("tmp")
+               if err == nil {
+                       callRepoInit = false
+               } else {
+                       if !os.IsNotExist(err) {
+                               t.Errorf("Stat'ing temporary directory: %v\n", err)
+                               return false
+                       }
+               }
+       }
+
+       if callRepoInit {
+               // mkdir tmp
+               if err := os.Mkdir("tmp", 0777); err != nil {
+                       t.Errorf("Making temporary path: %v\n", err)
+                       return false
+               }
+       }
+
+       if err := os.Chdir("tmp"); err != nil {
+               t.Errorf("cd tmp: %v\n", err)
+               return false
+       }
+
+       if callRepoInit {
+               // Initialize a current version of the repo
+               args := []string{"xsatool", "repo", "init"}
+               if ret := XsaMain(args); ret != 0 {
+                       t.Errorf("Command %v failed: %d\n", args, ret)
+                       return false
+               }
+       } else {
+               // Read existing version of repos
+               args := []string{"xsatool", "repo", "info"}
+               if ret := XsaMain(args); ret != 0 {
+                       t.Errorf("Command %v failed: %d\n", args, ret)
+                       return false
+               }
+       }
+
+       // Reset to a known state:
+       // (Want to be able to apply XSA-206 (backports) , XSA-211 (qemu), XSA-212-15 (xen)
+       // ~ March 27th
+       // Xen master    : ac9ff74
+       // qemu-upstream : acde9f3
+       // qemu-trad     : 8b4834e
+       // xsa           : bff3883
+       master := map[Tree]string{
+               "xen":   "ac9ff74",
+               "qemuu": "acde9f3",
+               "qemut": "8b4834e",
+               "xsa":   "bff3883",
+       }
+
+       updateMaster := func(t Tree) (err error) {
+               var r *Repo
+               if t == TreeXSA {
+                       r = &G.repos.xsa
+               } else {
+                       xr, prs := G.repos.XenRepos[t]
+                       if !prs {
+                               err = fmt.Errorf("Not present: %s\n", t)
+                               return
+                       }
+                       r = &xr.Repo
+               }
+
+               _, err = r.ResetBranch("master", master[t])
+               return
+       }
+
+       if err := ForEachTree(updateMaster); err != nil {
+               t.Errorf("Tree update failed: %v\n", err)
+               return false
+       }
+
+       // Delete:
+       // All xenversions > 4.8
+       //  4.8.0, 4.7.2, 4.6.5, 4.5.5
+
+       return true
+}
+
+func TestSystem(t *testing.T) {
+       if testing.Short() {
+               t.Skipf("Not running full system tests")
+       }
+
+       // Store the toplevel directory
+       topdir, err := os.Getwd()
+       if err != nil {
+               t.Errorf("Getwd failed?\n")
+               return
+       }
+
+       // Init and/or cd into the testing directory
+       if !InitRepo(t) {
+               t.Errorf("Could not initialize repo")
+               return
+       }
+
+       goto out
+
+out:
+       os.Chdir(topdir)
+
+       if FullClone {
+               // rm -rf tmp
+               if err := os.RemoveAll("tmp"); err != nil {
+                       t.Errorf("Removing temporary path: %v", err)
+                       return
+               }
+       }
+
+}