|
4 | 4 | "os" |
5 | 5 | "path/filepath" |
6 | 6 | "regexp" |
| 7 | + "runtime" |
7 | 8 | "slices" |
8 | 9 | "strings" |
9 | 10 | "testing" |
@@ -51,6 +52,21 @@ func wantErrFromYAML(t *testing.T, fileContent []byte) (want string, found bool) |
51 | 52 | return strings.TrimSpace(string(m[1])), true |
52 | 53 | } |
53 | 54 |
|
| 55 | +func shouldSkip(t *testing.T, parsed *ParsedSourceConfig, gotErr error) bool { |
| 56 | + t.Helper() |
| 57 | + |
| 58 | + if parsed == nil { |
| 59 | + return false |
| 60 | + } |
| 61 | + |
| 62 | + // not supported in windows and will raise an error we are ignoring here. |
| 63 | + if parsed.Common.Source == "journalctl" && runtime.GOOS == "windows" && strings.Contains(gotErr.Error(), "datasource 'journalctl' is not available") { |
| 64 | + return true |
| 65 | + } |
| 66 | + |
| 67 | + return false |
| 68 | +} |
| 69 | + |
54 | 70 | func TestParseSourceConfig(t *testing.T) { |
55 | 71 | ctx := t.Context() |
56 | 72 |
|
@@ -81,19 +97,25 @@ func TestParseSourceConfig(t *testing.T) { |
81 | 97 |
|
82 | 98 | if s.expectValid { |
83 | 99 | require.False(t, hasWant, "valid config must not include # wantErr: directive") |
84 | | - _, err := ParseSourceConfig(ctx, fileContent, metrics.AcquisitionMetricsLevelNone, nil) |
| 100 | + parsed, err := ParseSourceConfig(ctx, fileContent, metrics.AcquisitionMetricsLevelNone, nil) |
| 101 | + if shouldSkip(t, parsed, err) { |
| 102 | + return |
| 103 | + } |
85 | 104 | require.NoError(t, err) |
86 | 105 | return |
87 | 106 | } |
88 | 107 |
|
89 | 108 | // invalid |
| 109 | + |
90 | 110 | require.True(t, hasWant, "invalid config must include '# wantErr: <exact error>'") |
91 | 111 | require.NotEmpty(t, wantErr, "wantErr directive found but empty") |
92 | 112 |
|
93 | | - _, err := ParseSourceConfig(ctx, fileContent, metrics.AcquisitionMetricsLevelNone, nil) |
| 113 | + parsed, err := ParseSourceConfig(ctx, fileContent, metrics.AcquisitionMetricsLevelNone, nil) |
| 114 | + if shouldSkip(t, parsed, err) { |
| 115 | + return |
| 116 | + } |
94 | 117 | require.Error(t, err, "got no error, expected %q", wantErr) |
95 | 118 | assert.Equal(t, wantErr, err.Error()) |
96 | | -// assert.Contains(t, err.Error(), wantErr) |
97 | 119 | }) |
98 | 120 | } |
99 | 121 | }) |
|
0 commit comments