@@ -133,70 +133,88 @@ func TestEventLogRPC(t *testing.T) {
133
133
}
134
134
135
135
func TestEventLogHTTP (t * testing.T ) {
136
- if testing .Short () {
137
- t .Skip ("skipping integration test" )
136
+ var tests = []struct {
137
+ description string
138
+ endpoint string
139
+ }{
140
+ {
141
+ description : "/v1/event_log" ,
142
+ endpoint : "/v1/event_log" ,
143
+ },
144
+ {
145
+ description : "/v1/events" ,
146
+ endpoint : "/v1/events" ,
147
+ },
138
148
}
139
149
140
- httpAddr := randomPort ()
141
- teardown := setupSkaffoldWithArgs (t , "--rpc-http-port" , httpAddr )
142
- defer teardown ()
143
- time .Sleep (500 * time .Millisecond ) // give skaffold time to process all events
144
-
145
- httpResponse , err := http .Get (fmt .Sprintf ("http://localhost:%s/v1/events" , httpAddr ))
146
- if err != nil {
147
- t .Fatalf ("error connecting to gRPC REST API: %s" , err .Error ())
148
- }
149
- defer httpResponse .Body .Close ()
150
+ for _ , test := range tests {
151
+ t .Run (test .description , func (t * testing.T ) {
152
+ if testing .Short () {
153
+ t .Skip ("skipping integration test" )
154
+ }
150
155
151
- numEntries := 0
152
- var logEntries []proto.LogEntry
153
- for {
154
- e := make ([]byte , 1024 )
155
- l , err := httpResponse .Body .Read (e )
156
- if err != nil {
157
- t .Errorf ("error reading body from http response: %s" , err .Error ())
158
- }
159
- e = e [0 :l ] // remove empty bytes from slice
156
+ httpAddr := randomPort ()
157
+ teardown := setupSkaffoldWithArgs (t , "--rpc-http-port" , httpAddr )
158
+ defer teardown ()
159
+ time .Sleep (500 * time .Millisecond ) // give skaffold time to process all events
160
160
161
- // sometimes reads can encompass multiple log entries, since Read() doesn't count newlines as EOF.
162
- readEntries := strings .Split (string (e ), "\n " )
163
- for _ , entryStr := range readEntries {
164
- if entryStr == "" {
165
- continue
161
+ httpResponse , err := http .Get (fmt .Sprintf ("http://localhost:%s%s" , httpAddr , test .endpoint ))
162
+ if err != nil {
163
+ t .Fatalf ("error connecting to gRPC REST API: %s" , err .Error ())
166
164
}
167
- var entry proto.LogEntry
168
- // the HTTP wrapper sticks the proto messages into a map of "result" -> message.
169
- // attempting to JSON unmarshal drops necessary proto information, so we just manually
170
- // strip the string off the response and unmarshal directly to the proto message
171
- entryStr = strings .Replace (entryStr , "{\" result\" :" , "" , 1 )
172
- entryStr = entryStr [:len (entryStr )- 1 ]
173
- if err := jsonpb .UnmarshalString (entryStr , & entry ); err != nil {
174
- t .Errorf ("error converting http response to proto: %s" , err .Error ())
165
+ defer httpResponse .Body .Close ()
166
+
167
+ numEntries := 0
168
+ var logEntries []proto.LogEntry
169
+ for {
170
+ e := make ([]byte , 1024 )
171
+ l , err := httpResponse .Body .Read (e )
172
+ if err != nil {
173
+ t .Errorf ("error reading body from http response: %s" , err .Error ())
174
+ }
175
+ e = e [0 :l ] // remove empty bytes from slice
176
+
177
+ // sometimes reads can encompass multiple log entries, since Read() doesn't count newlines as EOF.
178
+ readEntries := strings .Split (string (e ), "\n " )
179
+ for _ , entryStr := range readEntries {
180
+ if entryStr == "" {
181
+ continue
182
+ }
183
+ var entry proto.LogEntry
184
+ // the HTTP wrapper sticks the proto messages into a map of "result" -> message.
185
+ // attempting to JSON unmarshal drops necessary proto information, so we just manually
186
+ // strip the string off the response and unmarshal directly to the proto message
187
+ entryStr = strings .Replace (entryStr , "{\" result\" :" , "" , 1 )
188
+ entryStr = entryStr [:len (entryStr )- 1 ]
189
+ if err := jsonpb .UnmarshalString (entryStr , & entry ); err != nil {
190
+ t .Errorf ("error converting http response to proto: %s" , err .Error ())
191
+ }
192
+ numEntries ++
193
+ logEntries = append (logEntries , entry )
194
+ }
195
+ if numEntries >= numLogEntries {
196
+ break
197
+ }
175
198
}
176
- numEntries ++
177
- logEntries = append (logEntries , entry )
178
- }
179
- if numEntries >= numLogEntries {
180
- break
181
- }
182
- }
183
199
184
- metaEntries , buildEntries , deployEntries := 0 , 0 , 0
185
- for _ , entry := range logEntries {
186
- switch entry .Event .GetEventType ().(type ) {
187
- case * proto.Event_MetaEvent :
188
- metaEntries ++
189
- case * proto.Event_BuildEvent :
190
- buildEntries ++
191
- case * proto.Event_DeployEvent :
192
- deployEntries ++
193
- default :
194
- }
200
+ metaEntries , buildEntries , deployEntries := 0 , 0 , 0
201
+ for _ , entry := range logEntries {
202
+ switch entry .Event .GetEventType ().(type ) {
203
+ case * proto.Event_MetaEvent :
204
+ metaEntries ++
205
+ case * proto.Event_BuildEvent :
206
+ buildEntries ++
207
+ case * proto.Event_DeployEvent :
208
+ deployEntries ++
209
+ default :
210
+ }
211
+ }
212
+ // make sure we have exactly 1 meta entry, 2 deploy entries and 2 build entries
213
+ testutil .CheckDeepEqual (t , 1 , metaEntries )
214
+ testutil .CheckDeepEqual (t , 2 , deployEntries )
215
+ testutil .CheckDeepEqual (t , 2 , buildEntries )
216
+ })
195
217
}
196
- // make sure we have exactly 1 meta entry, 2 deploy entries and 2 build entries
197
- testutil .CheckDeepEqual (t , 1 , metaEntries )
198
- testutil .CheckDeepEqual (t , 2 , deployEntries )
199
- testutil .CheckDeepEqual (t , 2 , buildEntries )
200
218
}
201
219
202
220
func TestGetStateRPC (t * testing.T ) {
0 commit comments