mirror of
https://github.com/3ybactuk/marketplace-go-service-project.git
synced 2025-10-30 14:03:45 +03:00
[hw-8] add: integration tests
This commit is contained in:
@@ -77,8 +77,6 @@ func (r *commentsRepo) InsertComment(ctx context.Context, comment *entity.Commen
|
||||
|
||||
r.idMx.Lock()
|
||||
id := r.curID*1000 + shardID
|
||||
r.curID++
|
||||
r.idMx.Unlock()
|
||||
|
||||
req := &InsertCommentParams{
|
||||
UserID: comment.UserID,
|
||||
@@ -92,6 +90,9 @@ func (r *commentsRepo) InsertComment(ctx context.Context, comment *entity.Commen
|
||||
return nil, err
|
||||
}
|
||||
|
||||
r.curID++
|
||||
r.idMx.Unlock()
|
||||
|
||||
return mapComment(c), nil
|
||||
}
|
||||
|
||||
@@ -125,12 +126,17 @@ func (r *commentsRepo) ListCommentsByUser(ctx context.Context, userID int64) ([]
|
||||
return nil, err2
|
||||
}
|
||||
|
||||
alreadyMerged := make(map[int64]struct{}, len(l1)+len(l2))
|
||||
merged := make([]*entity.Comment, 0, len(l1)+len(l2))
|
||||
for _, com := range l1 {
|
||||
merged = append(merged, mapComment(com))
|
||||
alreadyMerged[com.Sku] = struct{}{}
|
||||
}
|
||||
for _, com := range l2 {
|
||||
merged = append(merged, mapComment(com))
|
||||
if _, ok := alreadyMerged[com.Sku]; !ok {
|
||||
merged = append(merged, mapComment(com))
|
||||
alreadyMerged[com.Sku] = struct{}{}
|
||||
}
|
||||
}
|
||||
|
||||
return merged, nil
|
||||
|
||||
Reference in New Issue
Block a user