@@ -118,22 +118,19 @@ func (a *API) ServeHTTP(_ http.ResponseWriter, r *http.Request) {
118118 a .pushError (err )
119119 }
120120
121+ if kind == "increment_metric" {
122+ // Let's just output the metrics data and stop
123+ a .outputRequestData (kind , actual )
124+ return
125+ }
126+
121127 if err := a .pushResult (kind , actual ); err != nil {
122128 a .pushError (err )
123129 return
124130 }
125131
126132 if ! a .hasExpectations {
127- if a .writer != nil {
128- // output the data received to stdout
129- if err = json .NewEncoder (a .writer ).Encode (map [string ]any {
130- "type" : kind ,
131- "data" : actual .Data ,
132- }); err != nil {
133- // Fail so the user knows stdout is not working
134- log .Panicln ("Failed to write to stdout: " , err )
135- }
136- }
133+ a .outputRequestData (kind , actual )
137134 return
138135 }
139136
@@ -167,6 +164,19 @@ func (a *API) assertExpectation(kind string, actual *model.UpdateWrapper) {
167164 }
168165}
169166
167+ func (a * API ) outputRequestData (kind string , actual * model.UpdateWrapper ) {
168+ if a .writer != nil {
169+ // output the data received to stdout
170+ if err := json .NewEncoder (a .writer ).Encode (map [string ]any {
171+ "type" : kind ,
172+ "data" : actual .Data ,
173+ }); err != nil {
174+ // Fail so the user knows stdout is not working
175+ log .Panicln ("Failed to write to stdout: " , err )
176+ }
177+ }
178+ }
179+
170180func (a * API ) pushError (err error ) {
171181 escapedError := strings .ReplaceAll (err .Error (), "\n " , "" )
172182 escapedError = strings .ReplaceAll (escapedError , "\r " , "" )
@@ -213,6 +223,8 @@ func decodeWrapper(kind string, data []byte) (actual *model.UpdateWrapper, err e
213223 actual .Data , err = decode [model.RecordPackageManagerVersion ](data )
214224 case "record_update_job_error" :
215225 actual .Data , err = decode [model.RecordUpdateJobError ](data )
226+ case "increment_metric" :
227+ actual .Data , err = decode [model.IncrementMetric ](data )
216228 default :
217229 return nil , fmt .Errorf ("unexpected output type: %s" , kind )
218230 }
0 commit comments