From c2a88f0d2d9aa5486dcb1601eac31c15f1e091f4 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Mon, 2 Mar 2020 22:42:45 +0100 Subject: [PATCH] test string slice vs. json string slice --- internal/reqdata/parameter_test.go | 46 +++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/internal/reqdata/parameter_test.go b/internal/reqdata/parameter_test.go index c4a9ce4..5e0c753 100644 --- a/internal/reqdata/parameter_test.go +++ b/internal/reqdata/parameter_test.go @@ -32,7 +32,7 @@ func TestSimpleString(t *testing.T) { } } -func TestStringSlice(t *testing.T) { +func TestJsonStringSlice(t *testing.T) { p := Parameter{Parsed: false, File: false, Value: `["str1", "str2"]`} err := p.Parse() @@ -76,6 +76,50 @@ func TestStringSlice(t *testing.T) { } +func TestStringSlice(t *testing.T) { + p := Parameter{Parsed: false, File: false, Value: []string{"str1", "str2"}} + + err := p.Parse() + + if err != nil { + t.Errorf("unexpected error: <%s>", err) + t.FailNow() + } + + if !p.Parsed { + t.Errorf("expected parameter to be parsed") + t.FailNow() + } + + slice, canCast := p.Value.([]interface{}) + if !canCast { + t.Errorf("expected parameter to be a []interface{}") + t.FailNow() + } + + if len(slice) != 2 { + t.Errorf("expected 2 values, got %d", len(slice)) + t.FailNow() + } + + results := []string{"str1", "str2"} + + for i, res := range results { + + cast, canCast := slice[i].(string) + if !canCast { + t.Errorf("expected parameter %d to be a []string", i) + continue + } + if cast != res { + t.Errorf("expected first value to be '%s', got '%s'", res, cast) + continue + } + + } + +} + func TestJsonPrimitiveBool(t *testing.T) { tcases := []struct { Raw string