Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stringify metrics in test client #109

Open
ChrisBr opened this issue May 7, 2020 · 0 comments
Open

Stringify metrics in test client #109

ChrisBr opened this issue May 7, 2020 · 0 comments

Comments

@ChrisBr
Copy link
Collaborator

ChrisBr commented May 7, 2020

In our specs we use a test client to test if metrics were successfully written.

def write_point(name, options = {})
metrics << options.merge(name: name)
end

The test client is basically just an array with hashes. To simplify our specs we also have a custom rspec matcher expect_metric.

def expect_metric(name: "rails", **options)
expect(metrics).to include(
a_hash_including(options.merge(name: name))
)
end
def expect_no_metric(name: "rails", **options)
expect(metrics).not_to include(
a_hash_including(options.merge(name: name))
)
end

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant