From f56c44b338d3768cb65c48ecc692ffc07ace2f99 Mon Sep 17 00:00:00 2001 From: Jinn Koriech Date: Fri, 29 Apr 2022 19:33:05 +0100 Subject: [PATCH] fix(step): Handle assertions where the value type is int 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 https://github.com/sport24ru/terraform-provider-runscope/issues/19 Pair: @bogdan-largeanu @jinnko --- internal/runscope/schema/step.go | 8 ++++---- internal/runscope/step.go | 13 +++++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/internal/runscope/schema/step.go b/internal/runscope/schema/step.go index 964e867..7bb969a 100644 --- a/internal/runscope/schema/step.go +++ b/internal/runscope/schema/step.go @@ -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 { diff --git a/internal/runscope/step.go b/internal/runscope/step.go index 5c8a10b..9503bee 100644 --- a/internal/runscope/step.go +++ b/internal/runscope/step.go @@ -2,7 +2,9 @@ package runscope import ( "context" + "encoding/json" "fmt" + "github.com/terraform-providers/terraform-provider-runscope/internal/runscope/schema" ) @@ -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 { @@ -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, } }