Skip to content

Commit

Permalink
fix(step): Handle assertions where the value type is int
Browse files Browse the repository at this point in the history
We need to be able to use number types when creating, updating or
importing assertions of a response_status because the API returns a
number type for these field.

Fixes sport24ru#19

Pair: @bogdan-largeanu @jinnko
  • Loading branch information
jinnko committed Apr 29, 2022
1 parent 0f0885d commit f56c44b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
8 changes: 4 additions & 4 deletions internal/runscope/schema/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ type StepVariable struct {
}

type StepAssertion struct {
Source string `json:"source"`
Property string `json:"property"`
Comparison string `json:"comparison"`
Value string `json:"value"`
Source string `json:"source"`
Property string `json:"property"`
Comparison string `json:"comparison"`
Value json.RawMessage `json:"value"`
}

type StepAuth struct {
Expand Down
13 changes: 11 additions & 2 deletions internal/runscope/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package runscope

import (
"context"
"encoding/json"
"fmt"

"github.com/terraform-providers/terraform-provider-runscope/internal/runscope/schema"
)

Expand Down Expand Up @@ -49,11 +51,18 @@ func (sb *StepBase) setFromSchema(s *schema.Step) {
}
}
for i, a := range s.Assertions {
var value string
if len(a.Value) > 1 && a.Value[0] == '"' && a.Value[len(a.Value)-1] == '"' {
value = string(a.Value[1 : len(a.Value)-1])
} else {
value = string(a.Value)
}

sb.Assertions[i] = StepAssertion{
Source: a.Source,
Property: a.Property,
Comparison: a.Comparison,
Value: a.Value,
Value: value,
}
}
for header, values := range s.Headers {
Expand Down Expand Up @@ -172,7 +181,7 @@ func (sbo *StepBaseOpts) setRequest(sb *schema.StepBase) {
sb.Assertions[i] = schema.StepAssertion{
Source: a.Source,
Comparison: a.Comparison,
Value: a.Value,
Value: (json.RawMessage)(string('"') + string(a.Value) + string('"')),
Property: a.Property,
}
}
Expand Down

0 comments on commit f56c44b

Please sign in to comment.