1
1
package patrol_test
2
2
3
3
import (
4
+ "bufio"
4
5
"errors"
5
6
"fmt"
6
7
"io/ioutil"
@@ -27,13 +28,6 @@ type RepoTest struct {
27
28
28
29
// description of the test, what are trying to assess?
29
30
Description string
30
-
31
- // the git revision against which changes should be detected
32
- TestAgainstRevision string
33
-
34
- // the list of expected packages that should be flagged as changed between
35
- // HEAD and TestAgainstRevision
36
- ExpectedChangedPackages []string
37
31
}
38
32
39
33
func (test * RepoTest ) Run (t * testing.T ) {
@@ -75,19 +69,38 @@ func (test *RepoTest) Run(t *testing.T) {
75
69
})
76
70
require .NoError (t , err )
77
71
72
+ // avoid running patrol on first commit, there was nothing before
78
73
if previousCommit != "" {
74
+ expected := expectedChanges (t , tmp )
75
+
79
76
r , err := patrol .NewRepo (tmp )
80
77
require .NoError (t , err )
81
78
82
79
changes , err := r .ChangesFrom (previousCommit )
83
80
require .NoError (t , err )
84
- assert .ElementsMatch (t , test . ExpectedChangedPackages , changes , test .Name + ": expected changes do not match" )
81
+ assert .ElementsMatch (t , expected , changes , test .Name + ": expected changes do not match" )
85
82
}
86
83
87
84
previousCommit = commit .String ()
88
85
}
89
86
}
90
87
88
+ func expectedChanges (t * testing.T , dir string ) []string {
89
+ file , err := os .Open (filepath .Join (dir , "changes.patrol" ))
90
+ require .NoError (t , err )
91
+ defer file .Close ()
92
+
93
+ var changes []string
94
+ scanner := bufio .NewScanner (file )
95
+ for scanner .Scan () {
96
+ changes = append (changes , scanner .Text ())
97
+ }
98
+
99
+ require .NoError (t , scanner .Err ())
100
+
101
+ return changes
102
+ }
103
+
91
104
type RepoTests []RepoTest
92
105
93
106
func (tests RepoTests ) Run (t * testing.T ) {
0 commit comments