-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathquery_test.go
112 lines (100 loc) · 2.78 KB
/
query_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
package query_test
import (
"strings"
"testing"
"github.com/mlflow/mlflow-go-backend/pkg/tracking/service/query"
)
func TestValidQueries(t *testing.T) {
t.Parallel()
samples := []string{
"metrics.foobar = 40",
"metrics.foobar = 40 AND run_name = \"bouncy-boar-498\"",
"tags.\"mlflow.source.name\" = \"scratch.py\"",
"metrics.accuracy > 0.9",
"params.\"random_state\" = \"8888\"",
"params.`random_state` = \"8888\"",
"params.solver ILIKE \"L%\"",
"params.solver LIKE \"l%\"",
"datasets.digest IN ('77a19fc0')",
"attributes.run_id IN ('meh')",
}
for _, sample := range samples {
currentSample := sample
t.Run(currentSample, func(t *testing.T) {
t.Parallel()
_, err := query.ParseFilter(currentSample)
if err != nil {
t.Errorf("unexpected parse error: %v", err)
}
})
}
}
type invalidSample struct {
input string
expectedError string
}
//nolint:funlen
func TestInvalidQueries(t *testing.T) {
t.Parallel()
samples := []invalidSample{
{
input: "yow.foobar = 40",
expectedError: "invalid identifier",
},
{
input: "attributes.foobar = 40",
expectedError: "Invalid attribute key '{foobar}' specified. " +
"Valid keys are '[run_id run_name user_id status start_time end_time artifact_uri]'",
},
{
input: "datasets.foobar = 40",
expectedError: "Invalid dataset key '{foobar}' specified. " +
"Valid keys are '[run_id run_name user_id status start_time end_time artifact_uri]'",
},
{
input: "metric.yow = 'z'",
expectedError: "expected numeric value type for metric.",
},
{
input: "parameter.tag = 2",
expectedError: "expected a quoted string value",
},
{
input: "attributes.start_time = 'now'",
expectedError: "expected numeric value type for numeric attribute",
},
{
input: "attributes.run_name IN ('foo','bar')",
expectedError: "only the 'run_id' attribute supports comparison with a list",
},
{
input: "datasets.name = 40",
expectedError: "expected datasets.name to be either a string or list of strings",
},
{
input: "datasets.digest = 50",
expectedError: "expected datasets.digest to be either a string or list of strings",
},
{
input: "datasets.context = 60",
expectedError: "expected datasets.context to be either a string or list of strings",
},
}
for _, sample := range samples {
currentSample := sample
t.Run(currentSample.input, func(t *testing.T) {
t.Parallel()
_, err := query.ParseFilter(currentSample.input)
if err == nil {
t.Errorf("expected parse error but got nil")
}
if !strings.Contains(err.Error(), currentSample.expectedError) {
t.Errorf(
"expected error to contain %q, got %q",
currentSample.expectedError,
err.Error(),
)
}
})
}
}