-
-
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
Fix "index out of range" runtime error in repo_list tests #2376
Conversation
models/repo_list_test.go
Outdated
@@ -23,7 +23,9 @@ func TestSearchRepositoryByName(t *testing.T) { | |||
|
|||
assert.NotNil(t, repos) | |||
assert.NoError(t, err) | |||
assert.Equal(t, "test_repo_12", repos[0].Name) | |||
if len(repos) > 0 { |
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.
if assert.NotEmpty(repos) {
assert.Equal(t, "test_repo_12", repos[0].Name)
}
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.
You are right, my first tests :D
models/repo_list_test.go
Outdated
@@ -48,7 +50,9 @@ func TestSearchRepositoryByName(t *testing.T) { | |||
|
|||
assert.NotNil(t, repos) | |||
assert.NoError(t, err) | |||
assert.Equal(t, "test_repo_13", repos[0].Name) | |||
if len(repos) > 0 { |
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
4b5d6ae
to
fa08c27
Compare
it's a test, shouldn't you know what to expect (repo being or not being empty) ? |
@strk Sure, you should know what to expect. But that doesn't mean, you can write tests that can ends by |
Also, |
fa08c27
to
1ad56e5
Compare
Yep, an error about unexpected empty is great. I didn't notice the assert there. |
LGTM |
models/repo_list_test.go
Outdated
@@ -23,7 +23,9 @@ func TestSearchRepositoryByName(t *testing.T) { | |||
|
|||
assert.NotNil(t, repos) | |||
assert.NoError(t, err) | |||
assert.Equal(t, "test_repo_12", repos[0].Name) | |||
if assert.NotEmpty(t, repos) { |
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.
No. You should assert how many repos are there.
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 only need to know that there's more than 0 repos. (since we're accessing repos[0]
)
1ad56e5
to
571abc8
Compare
But it seems it's no need to do that? |
Fix runtime errors in specific conditions.