-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
[WIP] Added httptest for testing API #528
Conversation
I was hoping we could use the actual web package from Prometheus as the server. or if that would be too much trouble maybe run an actual Prometheus server in the background and run queries against that. The idea is that instead of mocking the server we should try to be as close as possible to an actual Prometheus server. This way any breaking changes would be caught quite easily. |
here is another example why we should try to use the actual api module or an actual prometheus server instead of mocking the responses. |
yes I'll try using the
|
the |
another approach would be to start an actual Prometheus server in the background and send api requests against it. |
@krasi-georgiev the Will be rewriting current tests now. Let me know if I should commit the vendor packages in another PR, or should I even commit the vendor directory as tests failing on go version < 10 |
Thanks , the progress looks promising 👍 .
why do you think that is? |
// return promAPI.Snapshot(context.Background(), skipHead) | ||
// } | ||
//} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The commented functions call admin api endpoints. Should I use a fakeDB for these, as in here:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes I think this will do.
It's probably something related to go modules, it's failing on v10 once I removed the vendor directory from the commit. Now only passes on v11. |
After #533 is merged, tests should pass again. |
Signed-off-by: Hrishikesh Barman <[email protected]>
Signed-off-by: Hrishikesh Barman <[email protected]>
Signed-off-by: Hrishikesh Barman <[email protected]>
…or packages Signed-off-by: Hrishikesh Barman <[email protected]>
Signed-off-by: Hrishikesh Barman <[email protected]>
Signed-off-by: Hrishikesh Barman <[email protected]>
Signed-off-by: Hrishikesh Barman <[email protected]>
Signed-off-by: Hrishikesh Barman <[email protected]>
Signed-off-by: Hrishikesh Barman <[email protected]>
Signed-off-by: Hrishikesh Barman <[email protected]>
Signed-off-by: Hrishikesh Barman <[email protected]>
Signed-off-by: Hrishikesh Barman <[email protected]>
Signed-off-by: Hrishikesh Barman <[email protected]>
The key problem with unit tests for Go 1.10 (and before) are the dependencies which are both included by this project and vendored in Besides these limitations, it feels a bit awkward for this module to depend on |
@simonpasquier yeah very valid point, thanks for the input. Can't think of another solution but starting some Prometheus server in the background. |
@krasi-georgiev in that case I think we should close this PR. I'll make another one that will send requests to an actual prometheus. I can add a comment on the top of the test that a local prometheus server should be running for this test. the test will fail if it does not detect a running prometheus server at 9090. is that a possible approach? |
Yeah a new PR is fine, but the test should be fully automated or we can't run it in the CI. |
@geekodour my take would be to deploy a Prometheus instance in the Travis CI infrastructure (you can run Docker containers within Travis) and skip the tests unless the |
@krasi-georgiev @simonpasquier okay. looking into it. thanks for the pointers. |
This is very much wip.
see #485
api_refactored_test.go
to show the new pattern usingnet/http/httptest
doAlertManagers
apiTest
URL
andDo
methods from the test file and usingURL
andDo
methods from the actual client at/api/client.go
apiTest
toapiTest_
andTestAPIs
toTestAPIs_
to avoid name collision with the originalapi_test.go
To make it easy to understand I've demonstrated this with
doAlertmanagers
only which is for the/api/v1/alertmanagers
endpoint.Now I tried importing
github.com/prometheus/prometheus/web/api/v1
but,If I uncomment importing
prometheus "github.com/prometheus/prometheus/web/api/v1"
I get the following error:Please let me know if this pattern can be followed for the rest of the tests.
cc: @krasi-georgiev