Skip to content

Commit

Permalink
fix(issue_match_handler_test): fixed flaky test (#321)
Browse files Browse the repository at this point in the history
  • Loading branch information
drochow authored Oct 22, 2024
1 parent 02bccec commit 5ff05e3
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions internal/app/issue_match/issue_match_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,28 +474,21 @@ var _ = Describe("OnComponentInstanceCreate", Label("app", "OnComponentInstanceC
db.AssertNumberOfCalls(GinkgoT(), "CreateIssueMatch", 2)
})

Context("when some issue matches already exist", func() {
Context("when issue matches already exist", func() {
BeforeEach(func() {
// Fake issues
issueMatch := test.NewFakeIssueMatch()
issueMatch.IssueId = 2 // issue2.Id
//when issueid is 2 return a fake issue match
db.On("GetIssueMatches", mock.MatchedBy(func(filter *entity.IssueMatchFilter) bool {
return *filter.IssueId[0] == int64(2)
})).Return([]entity.IssueMatch{issueMatch}, nil)
//when it is not 2 return none
db.On("GetIssueMatches", mock.MatchedBy(func(filter *entity.IssueMatchFilter) bool {
return *filter.IssueId[0] != int64(2)
})).Return([]entity.IssueMatch{}, nil)
db.On("GetIssueMatches", mock.Anything).Return([]entity.IssueMatch{issueMatch}, nil).Once()
})

It("should only create issue matches for new issues", func() {
It("should should not create new issues", func() {
// Mock CreateIssueMatch
db.On("CreateIssueMatch", mock.AnythingOfType("*entity.IssueMatch")).Return(&entity.IssueMatch{}, nil)
im.OnComponentVersionAssignmentToComponentInstance(db, componentInstanceID, componentVersionID)

// Verify that CreateIssueMatch was called only once (for the new issue)
db.AssertNumberOfCalls(GinkgoT(), "CreateIssueMatch", 1)
db.AssertNumberOfCalls(GinkgoT(), "CreateIssueMatch", 0)
})
})

Expand Down

0 comments on commit 5ff05e3

Please sign in to comment.