-
Notifications
You must be signed in to change notification settings - Fork 66
[+] add new testutil package
#1064
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
Conversation
Pull Request Test Coverage Report for Build 19968467613Details
💛 - Coveralls |
|
Great idea! Was on my todo list for a long time! :-) Let's go further! We need the same functions in many test packages anyway, not only sinks! The idea is:
|
I am not sure I understand this point. |
This means we will be moving all our |
If you setup a docker container, you want to return it to the test, right? If you setup a mock, you want the test to use it. That's what I mean under "return the environment". Every setup function should return test environment to the test case. No global vars or something like that. |
No, For example instead of func TestReadMetricSchemaType(t *testing.T) {
conn, err := pgxmock.NewPool()
assert.NoError(t, err)
...
}We could func TestReadMetricSchemaType(t *testing.T) {
conn, tearDown := testutil.SetupMock()
defer tearDown()
...
}or in case of the docker: func TestFoo(t *testing.T) {
pg, tearDown := testutil.SetupPgContainer()
defer tearDown()
connStr, err = pg.ConnectionString(ctx)
assert.NoError(t, err)
assert.NoError(t, db.Ping(ctx, connStr))
}Setup returns everything test case needs to run (environment) and the |
TestMain()testutil package
686f4ed to
3f751a9
Compare
|
One more thing. I don't like |
6dc5632 to
be0597b
Compare
be0597b to
5f636a7
Compare
- `mocks.go` for all mocks. - `setup.go` for all container/servers setup logic. - `helper_vars.go` for variables.
5f636a7 to
262254d
Compare
pashagolub
left a comment
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.
+1
testutilpackage that contains helper functions for different tests.SetupPostgresContainer()function that contains the pg container setup and termination logic.testutil/rpc.go.sinks/test_main.gofile containing theTestMain()for sinks tests.