influxdb-rails
influxdb-rails copied to clipboard
Stringify metrics in test client
In our specs we use a test client to test if metrics were successfully written.
https://github.com/influxdata/influxdb-rails/blob/1c9d6997c4add19f9189f1c62b2adff22644635e/spec/support/test_client.rb#L8-L10
The test client is basically just an array with hashes. To simplify our specs we also have a custom rspec matcher expect_metric
.
https://github.com/influxdata/influxdb-rails/blob/1c9d6997c4add19f9189f1c62b2adff22644635e/spec/support/matchers.rb#L7-L17
The test client and matchers do distinguish between strings and symbols. For instance, in our implementation we set the default location to :raw
and in our specs we need to assert also with a symbol.
# works
expect_metric(tags: a_hash_including(location: :raw))
# fails
expect_metric(tags: a_hash_including(location: "raw"))
I think this is a little bit surprising and caused me some time to debug. As InfluxDB only supports JSON anyway, I propose to just store string hashes in our test client and assert strings in our specs.