Browse code

integ-cli: fix bug and race in TestBuildSpaces

`TestBuildSpaces` is used to do string manipulation to redact timestamps
from compared cmd output. However it was assuming there is going to be
only one `time=".."` in the output --not the case on windows. Therefore
I wrote a regexp to redact all log timestamps.

Also the test used to have a copy/paste bug (see err1/err2). This fixes
that, too.

Signed-off-by: Ahmet Alp Balkan <ahmetalpbalkan@gmail.com>

Ahmet Alp Balkan authored on 2015/03/22 04:43:14
Showing 1 changed files
... ...
@@ -5124,9 +5124,13 @@ func TestBuildSpaces(t *testing.T) {
5124 5124
 		t.Fatal("Build 2 was supposed to fail, but didn't")
5125 5125
 	}
5126 5126
 
5127
+	removeLogTimestamps := func(s string) string {
5128
+		return regexp.MustCompile(`time="(.*?)"`).ReplaceAllString(s, `time=[TIMESTAMP]`)
5129
+	}
5130
+
5127 5131
 	// Skip over the times
5128
-	e1 := err1.Error()[strings.Index(err1.Error(), `level=`):]
5129
-	e2 := err2.Error()[strings.Index(err1.Error(), `level=`):]
5132
+	e1 := removeLogTimestamps(err1.Error())
5133
+	e2 := removeLogTimestamps(err2.Error())
5130 5134
 
5131 5135
 	// Ignore whitespace since that's what were verifying doesn't change stuff
5132 5136
 	if strings.Replace(e1, " ", "", -1) != strings.Replace(e2, " ", "", -1) {
... ...
@@ -5139,8 +5143,8 @@ func TestBuildSpaces(t *testing.T) {
5139 5139
 	}
5140 5140
 
5141 5141
 	// Skip over the times
5142
-	e1 = err1.Error()[strings.Index(err1.Error(), `level=`):]
5143
-	e2 = err2.Error()[strings.Index(err1.Error(), `level=`):]
5142
+	e1 = removeLogTimestamps(err1.Error())
5143
+	e2 = removeLogTimestamps(err2.Error())
5144 5144
 
5145 5145
 	// Ignore whitespace since that's what were verifying doesn't change stuff
5146 5146
 	if strings.Replace(e1, " ", "", -1) != strings.Replace(e2, " ", "", -1) {
... ...
@@ -5153,8 +5157,8 @@ func TestBuildSpaces(t *testing.T) {
5153 5153
 	}
5154 5154
 
5155 5155
 	// Skip over the times
5156
-	e1 = err1.Error()[strings.Index(err1.Error(), `level=`):]
5157
-	e2 = err2.Error()[strings.Index(err1.Error(), `level=`):]
5156
+	e1 = removeLogTimestamps(err1.Error())
5157
+	e2 = removeLogTimestamps(err2.Error())
5158 5158
 
5159 5159
 	// Ignore whitespace since that's what were verifying doesn't change stuff
5160 5160
 	if strings.Replace(e1, " ", "", -1) != strings.Replace(e2, " ", "", -1) {