-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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] Write tests for issue API #86
Conversation
// Does not check run user when the install lock is off. | ||
if InstallLock { | ||
// Does not check run user when the install lock is off or is running tests | ||
if InstallLock && AppRunMode != RUN_MODE_TEST { |
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.
Change code for testing is a bad practice
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.
I agree. This is a WIP, we should abstract things using interfaces. I am open for suggestions on how to do it right.
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.
Ok, thank you. It's very important to write testable code 👍
@@ -57,6 +57,10 @@ var ( | |||
EnableTiDB bool | |||
) | |||
|
|||
func Database() *sql.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.
And now we can execute SQL queries from handlers?
|
||
w, r := testutil.NewTestContext("GET", "/api/v1/repos/user1/foo/issues", "", nil, "1") | ||
testutil.ServeHTTP(w, r) | ||
So(w.Code, ShouldEqual, http.StatusOK) |
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.
Test which test nothing
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.
Well, it tests if /api/v1/repos/user1/foo/issues
returns status 200.
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.
I see, but it useless info. /api/v1/repos/user1/foo/issues
may returns 200 and {"foo": "bar"}
in response body. Or {"oops": "something went wrong"}
. Or Fuck the json
, etc…
@makhov glad that you are back :) |
@@ -263,6 +269,10 @@ var ( | |||
HasRobotsTxt bool | |||
) | |||
|
|||
func GiteaPath() string { |
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.
Exported functions should have be commented 😄
@@ -0,0 +1,31 @@ | |||
# THIS FILE EXISTS TO BE USED TO UNIT TESTS | |||
# DON'T CHANGE IT. THIS IS NOT THE FILE GOGS WILL USE IN PRODUCTION |
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.
GOGS
?
# THIS FILE EXISTS TO BE USED TO UNIT TESTS | ||
# DON'T CHANGE IT. THIS IS NOT THE FILE GOGS WILL USE IN PRODUCTION | ||
|
||
APP_NAME = Gogs: Go Git Service |
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.
Same as above
As I'm a big promoter of unit-tests, I'd prefer if we'd start with the model-tests instead. That way we get rid of a bunch of edge-cases before going for e2e-tests (integration, like these ones). It's also extremely hard to force edge-cases from this level, and the amount of tests would blow out of proportions. Testing models is easier since we know what goes in an out, and we don't have to force edge-cases. I also suggest that we use in-memory sqlite database |
So this need more discussion... |
Please don't merge yet. Opened for discussion on testing approach.
For context see #63
Edit: to run these tests: