Skip to content

Commit 42f2d45

Browse files
chore: add more valid and invalid testcases for TEXT format.
Signed-off-by: Electronic-Waste <[email protected]>
1 parent 4dfc659 commit 42f2d45

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

pkg/metricscollector/v1beta1/file-metricscollector/file-metricscollector_test.go

+48
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,27 @@ func TestCollectObservationLog(t *testing.T) {
130130
Value: "0.3634",
131131
},
132132
},
133+
{
134+
TimeStamp: "2024-03-04T17:55:08Z",
135+
Metric: &v1beta1.Metric{
136+
Name: "accuracy",
137+
Value: "100",
138+
},
139+
},
140+
{
141+
TimeStamp: "2024-03-04T17:55:08Z",
142+
Metric: &v1beta1.Metric{
143+
Name: "accuracy",
144+
Value: "888.333",
145+
},
146+
},
147+
{
148+
TimeStamp: "2024-03-04T17:55:08Z",
149+
Metric: &v1beta1.Metric{
150+
Name: "accuracy",
151+
Value: "-0.4759",
152+
},
153+
},
133154
{
134155
TimeStamp: time.Time{}.UTC().Format(time.RFC3339),
135156
Metric: &v1beta1.Metric{
@@ -140,6 +161,23 @@ func TestCollectObservationLog(t *testing.T) {
140161
},
141162
},
142163
},
164+
"Invalid case for logs in TEXT format": {
165+
filePath: filepath.Join(testTextDataPath, "invalid-value.log"),
166+
filters: []string{"{metricName: ([\\w|-]+), metricValue: ((-?\\d+)(\\.\\d+)?)}"},
167+
metrics: []string{"accuracy", "loss"},
168+
fileFormat: commonv1beta1.TextFormat,
169+
expected: &v1beta1.ObservationLog{
170+
MetricLogs: []*v1beta1.MetricLog{
171+
{
172+
TimeStamp: time.Time{}.UTC().Format(time.RFC3339),
173+
Metric: &v1beta1.Metric{
174+
Name: "accuracy",
175+
Value: consts.UnavailableMetricValue,
176+
},
177+
},
178+
},
179+
},
180+
},
143181
"Invalid file name": {
144182
filePath: "invalid",
145183
err: true,
@@ -331,7 +369,17 @@ func generateTEXTTestFiles() error {
331369
data: `2024-03-04T17:55:08Z INFO {metricName: accuracy, metricValue: 0.8078};{metricName: loss, metricValue: 0.5183}
332370
2024-03-04T17:55:08Z INFO {metricName: accuracy, metricValue: 0.6752}
333371
2024-03-04T17:55:08Z INFO {metricName: loss, metricValue: 0.3634}
372+
2024-03-04T17:55:08Z INFO {metricName: accuracy, metricValue: 100}
373+
2024-03-04T17:55:08Z INFO {metricName: accuracy, metricValue: 888.333}
374+
2024-03-04T17:55:08Z INFO {metricName: accuracy, metricValue: -0.4759}
334375
{metricName: loss, metricValue: 0.8671}`,
376+
},
377+
{
378+
fileName: "invalid-value.log",
379+
data: `2024-03-04T17:55:08Z INFO {metricName: accuracy, metricValue: .333}
380+
2024-03-04T17:55:08Z INFO {metricName: accuracy, metricValue: -.333}
381+
2024-03-04T17:55:08Z INFO {metricName: accuracy, metricValue: - 345.333}
382+
2024-03-04T17:55:08Z INFO {metricName: accuracy, metricValue: 888.}`,
335383
},
336384
{
337385
fileName: "invalid-format.log",

0 commit comments

Comments
 (0)