1
0

test(GODT-2746): Integration tests for reporting a problem

- Add function for checking header in form-data request

Bug reports are sent with multipart/form-data, and the function parses this,
then compares the needed field with the wanted
Also, added the step definition.

- Add functions for reporting a bug with changes

Be able to report a bug by changing the value of a single field, or multiple fields through a JSON format

- Add integration tests for reporting a problem
This commit is contained in:
Gjorgji Slamkov
2023-08-30 13:42:48 +02:00
parent 44e103edd5
commit c57b52ef23
4 changed files with 138 additions and 0 deletions

View File

@ -18,8 +18,11 @@
package tests
import (
"bufio"
"bytes"
"encoding/json"
"fmt"
"net/http"
"strings"
"github.com/cucumber/godog"
@ -87,6 +90,47 @@ func (s *scenario) theHeaderInTheRequestToHasSetTo(method, path, key, value stri
return nil
}
func (s *scenario) theHeaderInTheMultipartRequestToHasSetTo(method, path, key, value string) error {
// We have to exclude HTTP-Overrides to avoid race condition with the creating and sending of the draft message.
call, err := s.t.getLastCallExcludingHTTPOverride(method, path)
if err != nil {
return err
}
buf := new(bytes.Buffer)
if _, err := buf.WriteString(fmt.Sprintf("%s %s HTTP/1.1\r\n", call.Method, call.URL.Path)); err != nil {
return fmt.Errorf("failed to write request line: %w", err)
}
if err := call.RequestHeader.Write(buf); err != nil {
return fmt.Errorf("failed to write header: %w", err)
}
if _, err := buf.WriteString("\r\n"); err != nil {
return fmt.Errorf("failed to write header: %w", err)
}
if _, err := buf.Write(call.RequestBody); err != nil {
return fmt.Errorf("failed to write body: %w", err)
}
req, err := http.ReadRequest(bufio.NewReader(buf))
if err != nil {
return fmt.Errorf("failed to read request: %w", err)
}
if err := req.ParseMultipartForm(1 << 10); err != nil {
return fmt.Errorf("failed to parse multipart form: %w", err)
}
if haveKey := req.FormValue(key); haveKey != value {
return fmt.Errorf("have header %q, want %q", haveKey, value)
}
return nil
}
func (s *scenario) theBodyInTheRequestToIs(method, path string, value *godog.DocString) error {
// We have to exclude HTTP-Overrides to avoid race condition with the creating and sending of the draft message.
call, err := s.t.getLastCallExcludingHTTPOverride(method, path)