|
4 | 4 | "context" |
5 | 5 | "os" |
6 | 6 | "path/filepath" |
| 7 | + "strings" |
7 | 8 | "testing" |
8 | 9 | "time" |
9 | 10 |
|
@@ -144,18 +145,18 @@ metrics: |
144 | 145 | specialSourcesYaml := filepath.Join(tempDir, "special_sources.yaml") |
145 | 146 |
|
146 | 147 | // Build YAML with all special source names |
147 | | - yamlContent := "" |
| 148 | + var yamlContent strings.Builder |
148 | 149 | for _, name := range specialNames { |
149 | | - yamlContent += ` |
| 150 | + yamlContent.WriteString(` |
150 | 151 | - name: ` + name + ` |
151 | 152 | conn_str: ` + connStr + ` |
152 | 153 | kind: postgres |
153 | 154 | is_enabled: true |
154 | 155 | custom_metrics: |
155 | 156 | test_metric: 60 |
156 | | -` |
| 157 | +`) |
157 | 158 | } |
158 | | - require.NoError(t, os.WriteFile(specialSourcesYaml, []byte(yamlContent), 0644)) |
| 159 | + require.NoError(t, os.WriteFile(specialSourcesYaml, []byte(yamlContent.String()), 0644)) |
159 | 160 |
|
160 | 161 | os.Args = []string{ |
161 | 162 | "pgwatch", |
@@ -262,7 +263,7 @@ presets: |
262 | 263 |
|
263 | 264 | go main() |
264 | 265 |
|
265 | | - // Below tests are expected to run sequentially and depend on |
| 266 | + // Below tests are expected to run sequentially and depend on |
266 | 267 | // data generated by each other |
267 | 268 |
|
268 | 269 | t.Run("Ensure tag changes are applied", func(t *testing.T) { |
@@ -323,7 +324,7 @@ presets: |
323 | 324 | require.GreaterOrEqual(t, len(epochNsBefore), 2, "we need at least 2 measurements") |
324 | 325 |
|
325 | 326 | // Calculate interval before change |
326 | | - intervalBefore := float64(epochNsBefore[0] - epochNsBefore[1]) / 1e9 |
| 327 | + intervalBefore := float64(epochNsBefore[0]-epochNsBefore[1]) / 1e9 |
327 | 328 | assert.InDelta(t, 1.0, intervalBefore, 0.5, "interval should be approximately 1 second") |
328 | 329 |
|
329 | 330 | // Change interval to 2 seconds |
@@ -355,7 +356,7 @@ presets: |
355 | 356 | require.GreaterOrEqual(t, len(epochNsAfter), 2, "we need at least 2 measurements after interval change") |
356 | 357 |
|
357 | 358 | // Calculate interval after change |
358 | | - intervalAfter := float64(epochNsAfter[0] - epochNsAfter[1]) / 1e9 |
| 359 | + intervalAfter := float64(epochNsAfter[0]-epochNsAfter[1]) / 1e9 |
359 | 360 | assert.InDelta(t, 2.0, intervalAfter, 0.5, "new interval should be approximately 2 seconds") |
360 | 361 | assert.Greater(t, intervalAfter, intervalBefore, "new interval should be greater than old interval") |
361 | 362 | }) |
@@ -387,7 +388,7 @@ presets: |
387 | 388 | `SELECT count(*) FROM public.test_metric WHERE dbname = 'test_source'`).Scan(&countAfter) |
388 | 389 | require.NoError(t, err) |
389 | 390 |
|
390 | | - assert.LessOrEqual(t, countAfter - countBefore, 2) |
| 391 | + assert.LessOrEqual(t, countAfter-countBefore, 2) |
391 | 392 | }) |
392 | 393 |
|
393 | 394 | t.Run("Ensure preset intervals updates are applied - issue #1091", func(t *testing.T) { |
@@ -420,7 +421,7 @@ presets: |
420 | 421 | require.GreaterOrEqual(t, len(epochNsBefore), 2, "should have at least 2 measurements") |
421 | 422 |
|
422 | 423 | // Calculate interval before change |
423 | | - intervalBefore := float64(epochNsBefore[0] - epochNsBefore[1]) / 1e9 |
| 424 | + intervalBefore := float64(epochNsBefore[0]-epochNsBefore[1]) / 1e9 |
424 | 425 | assert.InDelta(t, 1.0, intervalBefore, 0.5, "interval should be approximately 1 second") |
425 | 426 |
|
426 | 427 | require.NoError(t, os.WriteFile(sourcesYaml, []byte(` |
@@ -463,7 +464,7 @@ presets: |
463 | 464 | require.GreaterOrEqual(t, len(epochNsAfter), 2, "should have at least 2 measurements") |
464 | 465 |
|
465 | 466 | // Calculate interval after change |
466 | | - intervalAfter := float64(epochNsAfter[0] - epochNsAfter[1]) / 1e9 |
| 467 | + intervalAfter := float64(epochNsAfter[0]-epochNsAfter[1]) / 1e9 |
467 | 468 | assert.InDelta(t, 2.0, intervalAfter, 0.5, "interval should be approximately 2 seconds") |
468 | 469 | }) |
469 | 470 |
|
|
0 commit comments