@@ -42,6 +42,7 @@ type validator struct {
4242 validateMapping bool
4343 validateConcurrency bool
4444 functionType string
45+ functionOutputFile string
4546 stdoutFile string
4647 stderrFile string
4748}
@@ -51,14 +52,14 @@ func newValidator(params validatorParams) *validator {
5152 validateMapping : params .validateMapping ,
5253 validateConcurrency : params .validateConcurrency ,
5354 functionType : params .functionType ,
55+ functionOutputFile : params .outputFile ,
5456 stdoutFile : defaultStdoutFile ,
5557 stderrFile : defaultStderrFile ,
5658 }
5759
5860 if ! params .useBuildpacks {
5961 v .funcServer = & localFunctionServer {
60- output : params .outputFile ,
61- cmd : params .runCmd ,
62+ cmd : params .runCmd ,
6263 }
6364 return & v
6465 }
@@ -68,7 +69,6 @@ func newValidator(params validatorParams) *validator {
6869 }
6970
7071 v .funcServer = & buildpacksFunctionServer {
71- output : params .outputFile ,
7272 source : params .source ,
7373 target : params .target ,
7474 runtime : params .runtime ,
@@ -81,7 +81,7 @@ func newValidator(params validatorParams) *validator {
8181func (v validator ) runValidation () error {
8282 log .Printf ("Validating for %s..." , * functionType )
8383
84- shutdown , err := v .funcServer .Start (v .stdoutFile , v .stderrFile )
84+ shutdown , err := v .funcServer .Start (v .stdoutFile , v .stderrFile , v . functionOutputFile )
8585 if shutdown != nil {
8686 defer shutdown ()
8787 }
@@ -101,7 +101,7 @@ func (v validator) errorWithLogsf(errorFmt string, paramsFmts ...interface{}) er
101101 if readErr != nil {
102102 logs = readErr .Error ()
103103 }
104- return fmt .Errorf ("%s, server logs: %s" , fmt .Sprintf (errorFmt , paramsFmts ... ), logs )
104+ return fmt .Errorf ("%s\n Server logs: %s" , fmt .Sprintf (errorFmt , paramsFmts ... ), logs )
105105}
106106
107107func (v validator ) readLogs () (string , error ) {
@@ -120,9 +120,10 @@ func (v validator) readLogs() (string, error) {
120120
121121// The HTTP function should copy the contents of the request into the response.
122122func (v validator ) validateHTTP (url string ) error {
123- want := map [ string ] string {
124- "res" : "PASS" ,
123+ type test struct {
124+ Res string `json: "res"`
125125 }
126+ want := test {Res : "PASS" }
126127
127128 req , err := json .Marshal (want )
128129 if err != nil {
@@ -138,13 +139,13 @@ func (v validator) validateHTTP(url string) error {
138139 return fmt .Errorf ("reading output file from HTTP function: %v" , err )
139140 }
140141
141- got := make ( map [ string ] string )
142+ got := test {}
142143 if err = json .Unmarshal (output , & got ); err != nil {
143- return fmt .Errorf ("failed to unmarshal json : %v" , err )
144+ return fmt .Errorf ("failed to unmarshal function output JSON : %v, function output: %q " , err , output )
144145 }
145146
146147 if ! cmp .Equal (got , want ) {
147- return fmt .Errorf ("unexpected HTTP output data: got %v , want %v " , got , want )
148+ return fmt .Errorf ("unexpected HTTP output data (format does not matter), got: %s , want: %s " , output , req )
148149 }
149150 return nil
150151}
0 commit comments