@@ -112,13 +112,14 @@ func TestHistoryGetById(t *testing.T) {
112
112
}
113
113
114
114
func TestHistoryGetByTarget (t * testing.T ) {
115
- history := & ResultHistory {MaxResults : 2 }
115
+ history := & ResultHistory {MaxResults : 3 }
116
116
117
- history .Add ("module" , "target-0" , fmt .Sprintf ("result %d" , history .nextId ), true )
118
- history .Add ("module" , "target-1" , fmt .Sprintf ("result %d" , history .nextId ), false )
117
+ history .Add ("module-0" , "target-0" , fmt .Sprintf ("result %d" , history .nextId ), true )
118
+ history .Add ("module-1" , "target-1" , fmt .Sprintf ("result %d" , history .nextId ), false )
119
+ history .Add ("module-0" , "target-1" , fmt .Sprintf ("result %d" , history .nextId ), false )
119
120
120
121
// Get a Result object for a target that exists
121
- resultTrue := history .GetByTarget ("target-0" )
122
+ resultTrue := history .GetByTarget ("target-0" , "" )
122
123
if resultTrue == nil {
123
124
t .Errorf ("Error finding the result in history by target for target-0" )
124
125
} else {
@@ -127,17 +128,37 @@ func TestHistoryGetByTarget(t *testing.T) {
127
128
}
128
129
}
129
130
130
- resultFalse := history .GetByTarget ("target-1" )
131
+ resultFalse := history .GetByTarget ("target-1" , "" )
131
132
if resultFalse == nil {
132
133
t .Errorf ("Error finding the result in history by target for target-1" )
133
134
} else {
134
135
if resultFalse .Target != "target-1" {
135
136
t .Errorf ("Error finding the result in history by target for target: expected \" %s\" and got \" %s\" " , "target-1" , resultFalse .Target )
136
137
}
138
+ if resultFalse .ModuleName != "module-1" {
139
+ t .Errorf ("Error finding the result in history by target for target: expected \" %s\" and got \" %s\" " , "module-1" , resultFalse .ModuleName )
140
+ }
137
141
}
138
142
139
143
// Get a Result object for a target that doesn't exist
140
- if history .GetByTarget ("target-5" ) != nil {
144
+ if history .GetByTarget ("target-5" , "" ) != nil {
141
145
t .Errorf ("Error finding the result in history by target for target-5" )
142
146
}
147
+
148
+ // Get a result by existing target and non-matching module
149
+ if history .GetByTarget ("target-1" , "module-5" ) != nil {
150
+ t .Errorf ("Incorrectly found a result in history by target for [target-1,module-5]" )
151
+ }
152
+
153
+ // Get a result by existing target and matching module
154
+ if result := history .GetByTarget ("target-1" , "module-1" ); result == nil {
155
+ t .Errorf ("Incorrectly found no result in history by target for [target-1,module-1]" )
156
+ } else {
157
+ if result .Target != "target-1" {
158
+ t .Errorf ("Error finding the result in history by target and module for target: expected \" %s\" and got \" %s\" " , "target-1" , result .Target )
159
+ }
160
+ if result .ModuleName != "module-1" {
161
+ t .Errorf ("Error finding the result in history by target and module for target: expected \" %s\" and got \" %s\" " , "module-1" , result .ModuleName )
162
+ }
163
+ }
143
164
}
0 commit comments