-
Notifications
You must be signed in to change notification settings - Fork 137
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
Setup integration test suite for db package #387
Setup integration test suite for db package #387
Conversation
Codecov Report
@@ Coverage Diff @@
## master #387 +/- ##
==========================================
- Coverage 28.71% 20.82% -7.89%
==========================================
Files 19 24 +5
Lines 1386 2170 +784
==========================================
+ Hits 398 452 +54
- Misses 961 1678 +717
- Partials 27 40 +13
Continue to review full report at Codecov.
|
This commit bootstrap a possible integration test suite for the db pkg. It uses TestContainers to create an manage container lifecycle as code inside a test case. In order to run those tests you need Docker enable, for this reason you have to execute them explicitly: $ go test -v ./db/_integration === RUN TestCreateTemplate === RUN TestCreateTemplate/happy-path-single-crete-template === PAUSE TestCreateTemplate/happy-path-single-crete-template === CONT TestCreateTemplate/happy-path-single-crete-template 2020/12/11 10:43:03 Starting container id: 0ea745bc8539 image: quay.io/testcontainers/ryuk:0.2.3 2020/12/11 10:43:03 Waiting for container id 0ea745bc8539 image: quay.io/testcontainers/ryuk:0.2.3 2020/12/11 10:43:03 Container is ready id: 0ea745bc8539 image: quay.io/testcontainers/ryuk:0.2.3 2020/12/11 10:43:03 Starting container id: a61bdbf3b7c3 image: postgres:13.1 2020/12/11 10:43:03 Waiting for container id a61bdbf3b7c3 image: postgres:13.1 2020/12/11 10:43:04 Container is ready id: a61bdbf3b7c3 image: postgres:13.1 db_test.go:64: applyed 5 migrations --- PASS: TestCreateTemplate (0.00s) --- PASS: TestCreateTemplate/happy-path-single-crete-template (2.42s) PASS ok github.com/tinkerbell/tink/db/_integration 2.676s Signed-off-by: Gianluca Arbezzano <gianarb92@gmail.com>
This commit add the integration tests as part of the CI checks Signed-off-by: Gianluca Arbezzano <gianarb92@gmail.com>
This commit adds more tests coming from #361 only for templates Signed-off-by: Gianluca Arbezzano <gianarb92@gmail.com>
db/_integration/db_test.go
Outdated
CHECK_DB: | ||
for ii := 0; ii < 5; ii++ { | ||
err = dbCon.Ping() | ||
if err != nil { | ||
t.Log(errors.Wrap(err, "db check")) | ||
time.Sleep(1 * time.Second) | ||
goto CHECK_DB | ||
} |
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.
this kind of doesn't make any sense right? If not ready go back to before the loop forever. If it is ready... make sure its ready 5 times?
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.
lgtm so far. Lets just set the tests up to run by default and call t.Skip() if it detects that docker is not available.
db/_integration/db_test.go
Outdated
ContainerRequest: testcontainers.ContainerRequest{ | ||
Image: "postgres:13.1", | ||
ExposedPorts: []string{"5432/tcp"}, | ||
WaitingFor: wait.ForLog("database system is ready to accept connections"), |
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.
we should add support to wait for something like wait.Exec and then we can just call pg_isready
.
@@ -31,6 +33,26 @@ func Parse(yamlContent []byte) (*Workflow, error) { | |||
return &workflow, nil | |||
} | |||
|
|||
// MustParse parse a slice of bytes to a template. It an error occurs the |
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.
can you add tests for these so codecov is happy?
I moved the test back to the db package as suggested by Manny and now tests automatically skip if Docker is not running. Signed-off-by: Gianluca Arbezzano <gianarb92@gmail.com>
This commit tests the two new functions introduced as utilities for template and workflow testing Signed-off-by: Gianluca Arbezzano <gianarb92@gmail.com>
Description
TestContainer is a library that spins up and down containers programmatically inside a test case. It is very comfortable to run integration tests and to set up requirements such as Postgres in our case.
This PR contains the first tests that validate the happy path for the CreateTemplate function.
Question
Right now in order to separate the tests requiring docker from the one who can run standalone I created a separate package
./db/_integration
that by default is not picked up bygo test ./...
The thread off here is that code coverage does not count the new package, even if it will be nice to have it included. A possible solution is to add a flag like:
if the flag is set the tests requiring docker will run. In this way, we should have code coverage counting integration tests.
Why is this needed
Because it is better to refactor a package when it is covered by tests.