]> xenbits.xensource.com Git - people/gdunlap/xsatool/commitdiff
systemtest: Always re-run 'repo init'
authorGeorge Dunlap <george.dunlap@citrix.com>
Fri, 23 Jun 2017 16:02:34 +0000 (17:02 +0100)
committerGeorge Dunlap <george.dunlap@citrix.com>
Mon, 26 Jun 2017 11:21:27 +0000 (12:21 +0100)
Always run `repo init`.  If `tmp` already exists, delete `tmp/.xsatool`.

Set a limit that ToolConfig.Load won't go up higher than, so that when
starting the test from 'scratch' we don't get "real" configurations
from any higher-level directoiries by accident.

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

diff --git a/main.go b/main.go
index 2e204a384e6e644dbc976e70ffe1c79b48dbc104..00515459e2cc8701941c0595ded2367c2809971b 100644 (file)
--- a/main.go
+++ b/main.go
@@ -61,6 +61,9 @@ var G struct {
                XenRepos map[Tree]*XenRepo
                xsa      Repo
        }
+       test struct {
+               topdir string
+       }
 }
 
 // Reset global state each run for testing sake
@@ -69,6 +72,7 @@ func globalReset() {
        G.config.Security = SecurityMeta{}
        G.repos.xsa = Repo{}
        G.repos.XenRepos = make(map[Tree]*XenRepo)
+       // Don't reset 'test' data
 }
 
 func XsaMain(args []string) int {
diff --git a/meta.go b/meta.go
index 54790186c4f4c1155d878868f259d68c451b35c1..53ce3216fe3f38fd0d0c01390563c012075f4eaf 100644 (file)
--- a/meta.go
+++ b/meta.go
@@ -87,6 +87,10 @@ func (tc *ToolConfig) Load() (err error) {
                                return fmt.Errorf("Trying to read %s: %v\n", configpath, err)
                        }
 
+                       if rootDir == G.test.topdir {
+                               return err
+                       }
+
                        rootDir = path.Clean(rootDir + "/..")
                        if rootDir == "/" {
                                // Should return 'true' for os.IsNotExist(err)
index 911bb57b46db3c927aaf5a2e18d33df219b12da2..4fb4108fcd50e97c477cec03d6e0ab2a8716506c 100644 (file)
@@ -51,7 +51,7 @@ var its = InitialTreeState{
 
 // Set up the repo in a known state.
 func InitRepo(st *SystemTest) bool {
-       callRepoInit := true
+       mkdir := true
 
        if FullClone {
                // Make temporary directory and cd to it
@@ -64,7 +64,7 @@ func InitRepo(st *SystemTest) bool {
                // Check to see if the directory exists
                _, err := os.Stat("tmp")
                if err == nil {
-                       callRepoInit = false
+                       mkdir = false
                } else {
                        if !os.IsNotExist(err) {
                                st.Errorf("Stat'ing temporary directory: %v\n", err)
@@ -73,7 +73,7 @@ func InitRepo(st *SystemTest) bool {
                }
        }
 
-       if callRepoInit {
+       if mkdir {
                // mkdir tmp
                if err := os.Mkdir("tmp", 0777); err != nil {
                        st.Errorf("Making temporary path: %v\n", err)
@@ -86,18 +86,28 @@ func InitRepo(st *SystemTest) bool {
                return false
        }
 
-       if callRepoInit {
-               // Initialize a current version of the repo
-               if ret := MainHarness("repo", "init"); ret != 0 {
-                       st.Errorf("repo init failed: %d\n", ret)
-                       return false
-               }
-       } else {
-               // Read existing version of repos
-               if ret := MainHarness("repo", "info"); ret != 0 {
-                       st.Errorf("repo info failed: %d\n", ret)
-                       return false
-               }
+       // Get rid of old .xsatool
+       if err := os.Remove(".xsatool"); err != nil && !os.IsNotExist(err) {
+               st.Errorf("Removing xsatool config file: %v", err)
+               return false
+       }
+
+       var err error
+       if G.test.topdir, err = os.Getwd(); err != nil {
+               st.Errorf("Getting topdir")
+       }
+
+       // Initialize a current version of the repo
+       if ret := MainHarness("repo", "init"); ret != 0 {
+               st.Errorf("repo init failed: %d\n", ret)
+               return false
+       }
+
+       if G.config.Tool.rootDir != G.test.topdir {
+               st.Errorf("Wrong root directory!  Wanted %s got %s\n",
+                       G.test.topdir,
+                       G.config.Tool.rootDir)
+               return false
        }
 
        updateBranches := func(t Tree) (err error) {