-
Notifications
You must be signed in to change notification settings - Fork 72
feat: setup unit tests with database #374
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
… sql and go migrations. This makes it easier to unit test where we just need sql migrations.
…ts to k8s mock will have them be automatically loaded.
…or method to encapsulate the behavior
… sql and go migrations. This makes it easier to unit test where we just need sql migrations.
…ts to k8s mock will have them be automatically loaded.
…or method to encapsulate the behavior
…o test/docker.database
…one after another
updated code to reflect this change and migrated it over.
…ion timestamp. Manually initializing them fixes this issue.
… and added tests for it
…mParameters" function.
Updated time tests to compare against time.Time{} because nanosecond difference comparison doesn't always work.
…ly detect a not-found condition and added tests for it.
…ould not be used. #breaking-change
| } | ||
|
|
||
| func Test_WorkspaceStatusToFieldMap(t *testing.T) { | ||
| testWorkspaceStatusToFieldMapLaunching(t) |
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 elaborate on the prefixes in test function names? I see:
test
Test
Test_
testClient (No _ here as opposed to the public funcs)
TestClient_
I am assuming TestClient_ are tests for methods on instances of DefaultTestClient(), and methods prefixed with testClient are for the private methods. But then looking at this line, that doesn't seem to be the case? Also should we consistently use _ for both public and private methods?
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.
General form is Test[<Struct>]_<Method> where <struct> is optional. This format comes from Goland - if you type in func Test.... it'll provide auto complete options to this.
TestClient_ are for methods on Client struct, which is a majority of the methods in pkg.
So we have TestClient_<method_name>. Methods like these are for direct tests of a method, they should completely test a method.
To test specific cases, you have testClient methods. Format is testClient<MethodName><Condition>
e.g. testClientGetWorkflowTemplateDBEmpty tests the GetWorkflowTemplateDB method, when the there is no template - empty.
TestClientGetWorkflowTemplateDB would call this as a child method.
TestClientGetWorfklowTemplateDB(...) {
testClientGetWorkflowTemplateDBEmpty(...)
}In the case where we have two methods where the only name difference is case, like
GetWorkflowTemplate vs getWorkflowTemplate I've used the private word.
testClientPrivateGetWorkflowTemplate
vs
testClientGetWorkflowTemplate which is for the exported member.
pkg/workspace_template_test.go
Outdated
| ` | ||
| ) | ||
|
|
||
| func TestParseWorkspaceSpec(t *testing.T) { |
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.
Should this be updated to match the new convention?
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'll update it.
|
Getting this error when running this branch: I have already ran this migration so I'm not sure why it is trying it again. |
Are you running it in test mode, or just general build mode? |
Running in debug mode - not testing. |
…em if they were ran earlier in the goose_db_version db table.
… printed after the goose message, which was a bit confusing.
|
When a test fails, the test container is not stopped and I get this error when trying to run tests: |
What this PR does:
Sets up unit testing with a live database.
Fixes onepanelio/core#
Special notes for your reviewer:
run
make test-runto run the tests.