Skip to content

Commit

Permalink
add test case for fixture array parser (#963)
Browse files Browse the repository at this point in the history
  • Loading branch information
etsai-stripe committed Sep 2, 2022
1 parent 90b2b70 commit 84c878c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions pkg/fixtures/parsers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,3 +313,28 @@ func TestParseWithEnvSubstring(t *testing.T) {

fs.Remove(envPath)
}

func TestParseArray(t *testing.T) {
jsonData := gjson.Parse(`{"id": "cust_bend123456789", "timezones": ["Europe/Brussels", "Europe/Berlin"]}`)

fxt := Fixture{}
fxt.responses = make(map[string]gjson.Result)
fxt.responses["cust_bender"] = jsonData

data := make(map[string]interface{})
data["customer"] = "${cust_bender:id}"
data["timezones"] = "${cust_bender:timezones}"
data["first_timezone"] = "${cust_bender:timezones.0}"
data["second_timezone"] = "${cust_bender:timezones.1}"
data["third_timezone"] = "${cust_bender:timezones.2|notimezonefound}"

output, _ := fxt.parseInterface(data)
sort.Strings(output)

require.Equal(t, len(output), 5)
require.Equal(t, "customer=cust_bend123456789", output[0])
require.Equal(t, "first_timezone=Europe/Brussels", output[1])
require.Equal(t, "second_timezone=Europe/Berlin", output[2])
require.Equal(t, "third_timezone=notimezonefound", output[3])
require.Equal(t, "timezones=[\"Europe/Brussels\", \"Europe/Berlin\"]", output[4])
}

0 comments on commit 84c878c

Please sign in to comment.