Skip to content

Commit

Permalink
fix assert
Browse files Browse the repository at this point in the history
  • Loading branch information
Begi committed May 17, 2023
1 parent 2abc4cd commit 5249c85
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
2 changes: 1 addition & 1 deletion executors/tavern/assert.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func init() {
// if assertion fails
func AssertResponse(actual interface{}, expected ...interface{}) error {

result, ok := actual.(Result)
result, ok := actual.(Actual)
if !ok {
return fmt.Errorf("bad actual type: expected: Result, actual: %T", actual)
}
Expand Down
30 changes: 18 additions & 12 deletions executors/tavern/tavern.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,14 @@ type Executor struct {
Response Response `json:"response" yaml:"response"`
}

type Actual struct {
Actual Response
Expected Response
}

// Result represents a step result. Json and yaml descriptor are used for json output
type Result struct {
Actual Response
Expected Response
Actual Actual
TimeSeconds float64 `json:"time_seconds,omitempty" yaml:"time_seconds,omitempty"`
Err string `json:"err,omitempty" yaml:"err,omitempty"`
}
Expand All @@ -101,7 +105,7 @@ func (Executor) ZeroValueResult() interface{} {

// GetDefaultAssertions return default assertions for this executor
func (Executor) GetDefaultAssertions() *venom.StepAssertions {
return &venom.StepAssertions{Assertions: []venom.Assertion{}}
return &venom.StepAssertions{Assertions: []venom.Assertion{"result.Actual AssertResponse"}}
}

// Run execute TestStep
Expand All @@ -120,9 +124,11 @@ func (Executor) Run(ctx context.Context, step venom.TestStep) (interface{}, erro
}
e.Request.MultipartForm = mapRequest["multipart_form"]

r := Result{}

r.Expected = e.Response
r := Result{
Actual: Actual{
Expected: e.Response,
},
}

workdir := venom.StringVarFromCtx(ctx, "venom.testsuite.workdir")

Expand Down Expand Up @@ -231,28 +237,28 @@ func (Executor) Run(ctx context.Context, step venom.TestStep) (interface{}, erro
if errr != nil {
return nil, errr
}
r.Actual.Body = string(bb)
r.Actual.Actual.Body = string(bb)

var m interface{}
decoder := json.NewDecoder(strings.NewReader(string(bb)))
if err := decoder.Decode(&m); err == nil {
r.Actual.JSON = m
r.Actual.Actual.JSON = m
}
}
}

if !e.Request.SkipHeaders {
r.Actual.Headers = make(map[string]string)
r.Actual.Actual.Headers = make(map[string]string)
for k, v := range resp.Header {
if strings.ToLower(k) == "set-cookie" {
r.Actual.Headers[k] = strings.Join(v, "; ")
r.Actual.Actual.Headers[k] = strings.Join(v, "; ")
} else {
r.Actual.Headers[k] = v[0]
r.Actual.Actual.Headers[k] = v[0]
}
}
}

r.Actual.StatusCode = resp.StatusCode
r.Actual.Actual.StatusCode = resp.StatusCode
return r, nil
}

Expand Down

0 comments on commit 5249c85

Please sign in to comment.