Skip to content

Commit b7b3897

Browse files
committed
test: improve tests
1 parent f7ef708 commit b7b3897

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

internal/repository/github/github.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (s githubService) CloseVulnerabilityIssue(project repository.Project) (err
8888
return nil
8989
}
9090
state := "closed"
91-
_, _, err = s.client.UpdateIssue(project.GroupOrOwner, project.Name, issue.GetNumber(), &github.IssueRequest{
91+
_, _, err = s.client.UpdateIssue(project.GroupOrOwner, project.Name, issue.GetNumber(), &github.IssueRequest{
9292
State: &state,
9393
})
9494
if err != nil {

internal/repository/github/github_test.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ func TestDownload(t *testing.T) {
173173
}
174174

175175
func TestOpenVulnerabilityIssue(t *testing.T) {
176-
title := "666"
176+
title := repository.VulnerabilityIssueTitle
177177
mockClient := mockService{}
178178
mockClient.On("ListRepositoryIssues", mock.Anything, mock.Anything, mock.Anything).Return([]*github.Issue{}, &github.Response{}, nil)
179179
mockClient.On("CreateIssue", mock.Anything, mock.Anything, mock.Anything).Return(&github.Issue{Title: &title}, &github.Response{}, nil)
@@ -183,18 +183,22 @@ func TestOpenVulnerabilityIssue(t *testing.T) {
183183
i, err := svc.OpenVulnerabilityIssue(repository.Project{GroupOrOwner: "group", Name: "repo"}, "report")
184184
assert.Nil(t, err)
185185
assert.NotNil(t, i)
186-
assert.Equal(t, "666", i.Title)
186+
assert.Equal(t, repository.VulnerabilityIssueTitle, i.Title)
187+
mockClient.AssertExpectations(t)
187188
}
188189

189190
func TestCloseVulnerabilityIssue(t *testing.T) {
190-
title := "288"
191+
title := repository.VulnerabilityIssueTitle
192+
state := "open"
191193
mockClient := mockService{}
192-
mockClient.On("ListRepositoryIssues", mock.Anything, mock.Anything, mock.Anything).Return([]*github.Issue{{Title: &title}}, &github.Response{}, nil)
194+
mockClient.On("ListRepositoryIssues", mock.Anything, mock.Anything, mock.Anything).Return([]*github.Issue{{Title: &title, State: &state}}, &github.Response{}, nil)
195+
mockClient.On("UpdateIssue", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(&github.Issue{}, &github.Response{}, nil)
193196

194197
svc := githubService{client: &mockClient}
195198

196199
err := svc.CloseVulnerabilityIssue(repository.Project{GroupOrOwner: "group", Name: "repo"})
197200
assert.Nil(t, err)
201+
mockClient.AssertExpectations(t)
198202
}
199203

200204
func TestCloseVulnerabilityIssueNoIssue(t *testing.T) {
@@ -205,6 +209,7 @@ func TestCloseVulnerabilityIssueNoIssue(t *testing.T) {
205209

206210
err := svc.CloseVulnerabilityIssue(repository.Project{GroupOrOwner: "group", Name: "repo"})
207211
assert.Nil(t, err)
212+
mockClient.AssertExpectations(t)
208213
}
209214

210215
type mockService struct {

0 commit comments

Comments
 (0)