]> xenbits.xensource.com Git - people/gdunlap/xsatool.git/commitdiff
systemtest: Implement --clean option to start from scratch
authorGeorge Dunlap <george.dunlap@citrix.com>
Fri, 23 Jun 2017 16:20:54 +0000 (17:20 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Mon, 26 Jun 2017 11:21:43 +0000 (12:21 +0100)
Pass all arguments to systemtest.  Use the `flag` package to read `-clean`.

Signed-off-by: George Dunlap <george.dunlap@citrix.com>
main.go
systemtest.go

diff --git a/main.go b/main.go
index 00515459e2cc8701941c0595ded2367c2809971b..de18d59d94710b6455c38d240a1f0fc2fe690db1 100644 (file)
--- a/main.go
+++ b/main.go
@@ -94,6 +94,12 @@ func XsaMain(args []string) int {
 
        tgt := args[1]
        args = args[2:]
+
+       // Check for this first
+       if tgt == "systemtest" {
+               return MainSystemTest(args)
+       }
+
        var cmd string
        if len(args) > 0 {
                cmd = args[0]
@@ -164,8 +170,6 @@ func XsaMain(args []string) int {
                        fmt.Printf("Unknown command: %s\n", cmd)
                        return 1
                }
-       } else if tgt == "systemtest" {
-               return MainSystemTest()
        }
 
        if loadConfig {
index 4fb4108fcd50e97c477cec03d6e0ab2a8716506c..19d0d8ee4a2a090409018b0fdb1f2aa0226bb3be 100644 (file)
@@ -1,6 +1,7 @@
 package main
 
 import (
+       "flag"
        "fmt"
        "os"
        "path/filepath"
@@ -17,7 +18,10 @@ func (st *SystemTest) Errorf(s string, args ...interface{}) {
 
 // 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
+
+var TestFlags struct {
+       Clean bool
+}
 
 type InitialTreeState map[Tree]*map[string]string
 
@@ -53,7 +57,8 @@ var its = InitialTreeState{
 func InitRepo(st *SystemTest) bool {
        mkdir := true
 
-       if FullClone {
+       if TestFlags.Clean {
+               fmt.Printf("Deleting old repositories...\n")
                // Make temporary directory and cd to it
                // rm -rf tmp
                if err := os.RemoveAll("tmp"); err != nil {
@@ -180,7 +185,7 @@ func InitRepo(st *SystemTest) bool {
        }
 
        // Delete files potentially left over from previous runs
-       if !FullClone {
+       if !TestFlags.Clean {
                // rm xsa.git/*.meta
                files, err := filepath.Glob("xsa.git/*.meta")
                if err != nil {
@@ -508,9 +513,20 @@ func Story206(st *SystemTest) bool {
        return true
 }
 
-func MainSystemTest() (ret int) {
+func MainSystemTest(args []string) (ret int) {
        var st SystemTest
 
+       flags := flag.NewFlagSet("xsatool:systemtest", flag.ContinueOnError)
+
+       flags.BoolVar(&TestFlags.Clean, "clean", false, "Delete and re-clone repository before test.  Slower but more complete")
+
+       if err := flags.Parse(args); err != nil {
+               if err != flag.ErrHelp {
+                       fmt.Printf("Error parsing args: %v\n", err)
+               }
+               return 1
+       }
+
        // Fail unless we make it through the gauntlet
        ret = 1
 
@@ -548,15 +564,6 @@ func MainSystemTest() (ret int) {
 out:
        os.Chdir(topdir)
 
-       if FullClone {
-               // rm -rf tmp
-               if err := os.RemoveAll("tmp"); err != nil {
-                       st.Errorf("Removing temporary path: %v", err)
-                       ret = 1
-                       return
-               }
-       }
-
        if st.failed {
                fmt.Print("System test: FAILED\n")
        } else {