logs_model.test.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. import { dedupLogRows, LogsDedupStrategy, LogsModel } from '../logs_model';
  2. describe('dedupLogRows()', () => {
  3. test('should return rows as is when dedup is set to none', () => {
  4. const logs = {
  5. rows: [
  6. {
  7. entry: 'WARN test 1.23 on [xxx]',
  8. },
  9. {
  10. entry: 'WARN test 1.23 on [xxx]',
  11. },
  12. ],
  13. };
  14. expect(dedupLogRows(logs as LogsModel, LogsDedupStrategy.none).rows).toMatchObject(logs.rows);
  15. });
  16. test('should dedup on exact matches', () => {
  17. const logs = {
  18. rows: [
  19. {
  20. entry: 'WARN test 1.23 on [xxx]',
  21. },
  22. {
  23. entry: 'WARN test 1.23 on [xxx]',
  24. },
  25. {
  26. entry: 'INFO test 2.44 on [xxx]',
  27. },
  28. {
  29. entry: 'WARN test 1.23 on [xxx]',
  30. },
  31. ],
  32. };
  33. expect(dedupLogRows(logs as LogsModel, LogsDedupStrategy.exact).rows).toEqual([
  34. {
  35. duplicates: 1,
  36. entry: 'WARN test 1.23 on [xxx]',
  37. },
  38. {
  39. duplicates: 0,
  40. entry: 'INFO test 2.44 on [xxx]',
  41. },
  42. {
  43. duplicates: 0,
  44. entry: 'WARN test 1.23 on [xxx]',
  45. },
  46. ]);
  47. });
  48. test('should dedup on number matches', () => {
  49. const logs = {
  50. rows: [
  51. {
  52. entry: 'WARN test 1.2323423 on [xxx]',
  53. },
  54. {
  55. entry: 'WARN test 1.23 on [xxx]',
  56. },
  57. {
  58. entry: 'INFO test 2.44 on [xxx]',
  59. },
  60. {
  61. entry: 'WARN test 1.23 on [xxx]',
  62. },
  63. ],
  64. };
  65. expect(dedupLogRows(logs as LogsModel, LogsDedupStrategy.numbers).rows).toEqual([
  66. {
  67. duplicates: 1,
  68. entry: 'WARN test 1.2323423 on [xxx]',
  69. },
  70. {
  71. duplicates: 0,
  72. entry: 'INFO test 2.44 on [xxx]',
  73. },
  74. {
  75. duplicates: 0,
  76. entry: 'WARN test 1.23 on [xxx]',
  77. },
  78. ]);
  79. });
  80. test('should dedup on signature matches', () => {
  81. const logs = {
  82. rows: [
  83. {
  84. entry: 'WARN test 1.2323423 on [xxx]',
  85. },
  86. {
  87. entry: 'WARN test 1.23 on [xxx]',
  88. },
  89. {
  90. entry: 'INFO test 2.44 on [xxx]',
  91. },
  92. {
  93. entry: 'WARN test 1.23 on [xxx]',
  94. },
  95. ],
  96. };
  97. expect(dedupLogRows(logs as LogsModel, LogsDedupStrategy.signature).rows).toEqual([
  98. {
  99. duplicates: 3,
  100. entry: 'WARN test 1.2323423 on [xxx]',
  101. },
  102. ]);
  103. });
  104. });