Skip to content

Commit

Permalink
k6runner/test: ensure HTTPRunRequest unmarshals into flattened struct
Browse files Browse the repository at this point in the history
  • Loading branch information
roobre committed Sep 30, 2024
1 parent 74a563f commit 083d43b
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions internal/k6runner/k6runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"net"
"net/http"
"net/http/httptest"
"reflect"
"sort"
"strconv"
"strings"
Expand Down Expand Up @@ -118,7 +117,12 @@ func TestHttpRunnerRun(t *testing.T) {
require.Equal(t, http.MethodPost, r.Method)
require.Equal(t, "application/json", r.Header.Get("Content-Type"))

var req HTTPRunRequest
var req struct {
Script []byte `json:"script"`
Settings Settings `json:"settings"`
NotAfter time.Time `json:"notAfter"`
}

err := json.NewDecoder(r.Body).Decode(&req)
if err != nil {
t.Logf("decoding body: %v", err)
Expand All @@ -127,13 +131,6 @@ func TestHttpRunnerRun(t *testing.T) {
return
}

if !reflect.DeepEqual(script, req.Script) {
t.Log("unexpected script in request")
t.Fail()
w.WriteHeader(400) // Use 400 as the client won't retry this failure.
return
}

if time.Since(req.NotAfter) > time.Hour || time.Until(req.NotAfter) > time.Hour {
t.Log("unexpected value for NotAfter too far from the present")
t.Fail()
Expand Down

0 comments on commit 083d43b

Please sign in to comment.