Skip to content

Commit

Permalink
refactor:update mocks for used mocks in mongo parser (keploy#1610)
Browse files Browse the repository at this point in the history
  • Loading branch information
shivamsouravjha authored Feb 23, 2024
1 parent 76684aa commit 6e18c49
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/hooks/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,6 @@ func (h *Hook) SetTcsMocks(m []*models.Mock) {
func (h *Hook) SetConfigMocks(m []*models.Mock) {
h.configMocks.deleteAll()
for index, mock := range m {
h.UpdateConsumedMocks(mock.Name, false)
mock.TestModeInfo.SortOrder = index
mock.TestModeInfo.Id = index
h.configMocks.insert(mock.TestModeInfo, mock)
Expand All @@ -206,6 +205,9 @@ func (h *Hook) SetConfigMocks(m []*models.Mock) {

func (h *Hook) UpdateConfigMock(oldMock *models.Mock, newMock *models.Mock) bool {
isUpdated := h.configMocks.update(oldMock.TestModeInfo, newMock.TestModeInfo, newMock)
if isUpdated {
h.UpdateConsumedMocks(oldMock.Name, false)
}
return isUpdated
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/proxy/integrations/mongoparser/mongoparser.go
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ func decodeOutgoingMongo(requestBuffer []byte, clientConn, destConn net.Conn, h
if bestMatchIndex == -1 || maxMatchScore == 0.0 {
logger.Debug("the mongo request do not matches with any config mocks", zap.Any("request", mongoRequests))
continue
} else {
h.UpdateConfigMock(configMocks[bestMatchIndex], configMocks[bestMatchIndex])
}
for _, mongoResponse := range configMocks[bestMatchIndex].Spec.MongoResponses {
switch mongoResponse.Header.Opcode {
Expand Down

0 comments on commit 6e18c49

Please sign in to comment.