You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// UpdateFailedQueryCache returns true if query is cached so that callsite can increase counter, returns message as a string for callsite to log outcome
t.Fatalf("Expected cache to be created, but got nil")
16
17
}
17
-
ifmsg!="" {
18
-
t.Fatalf("Expected no error message, but got: %s", msg)
18
+
iferr!=nil {
19
+
t.Fatalf("Expected no error message, but got: %s", err.Error())
19
20
}
20
21
}
21
22
22
23
funcTestUpdateFailedQueryCache(t*testing.T) {
23
24
cache, _:=NewFailedQueryCache(2)
24
-
lruCache:=cache.LruCache
25
25
26
26
tests:= []struct {
27
-
namestring
28
-
errerror
29
-
queryExpressionNormalizedstring
30
-
queryExpressionRangeLengthint
31
-
expectedResultbool
32
-
expectedMessageContainsstring
27
+
namestring
28
+
errerror
29
+
query url.Values
30
+
expectedResultbool
31
+
expectedMessagestring
33
32
}{
34
33
{
35
-
name: "No error code in error message",
36
-
err: errors.New("no error code here"),
37
-
queryExpressionNormalized: "test_query",
38
-
queryExpressionRangeLength: 60,
39
-
expectedResult: false,
40
-
expectedMessageContains: "msg: String regex conversion error, normalized query: test_query, query range seconds: 60, updating cache for error: no error code here",
34
+
name: "No error code in error message",
35
+
err: errors.New("no error code here"),
36
+
query: url.Values{
37
+
"start": {"100"},
38
+
"end": {"200"},
39
+
"query": {"test_query"},
40
+
},
41
+
expectedResult: false,
42
+
expectedMessage: "msg: String regex conversion error, normalized query: test_query, query range seconds: 100, updating cache for error: no error code here",
41
43
},
42
44
{
43
-
name: "Non-cacheable error code",
44
-
err: errors.New("Code(500)"),
45
-
queryExpressionNormalized: "test_query",
46
-
queryExpressionRangeLength: 60,
47
-
expectedResult: false,
48
-
expectedMessageContains: "msg: Query not cached due to non-cacheable error code, normalized query: test_query, query range seconds: 60, updating cache for error: Code(500)",
expectedMessage: "msg: Query not cached due to non-cacheable error code, normalized query: test_query, query range seconds: 100, updating cache for error: serads;ajkvsd( Code(500) code)asd",
49
54
},
50
55
{
51
-
name: "Cacheable error code",
52
-
err: errors.New("Code(408)"),
53
-
queryExpressionNormalized: "test_query",
54
-
queryExpressionRangeLength: 60,
55
-
expectedResult: true,
56
-
expectedMessageContains: "msg: Cached a failed query, normalized query: test_query, range seconds: 60, updating cache for error: Code(408)",
56
+
name: "Cacheable error code",
57
+
err: errors.New("This is a random error Code(408). It is random."),
58
+
query: url.Values{
59
+
"start": {"100"},
60
+
"end": {"200"},
61
+
"query": {"test_query"},
62
+
},
63
+
expectedResult: true,
64
+
expectedMessage: "msg: Cached a failed query, normalized query: test_query, range seconds: 100, updating cache for error: This is a random error Code(408). It is random.",
65
+
},
66
+
67
+
{
68
+
name: "Adding query with whitespace and ensuring it is normalized",
69
+
err: errors.New("Adding error with query that has whitespace and tabs Code(408). Let's see what happens."),
70
+
query: url.Values{
71
+
"start": {"100"},
72
+
"end": {"200"},
73
+
"query": {"\n\t tes \t t query \n"},
74
+
},
75
+
expectedResult: true,
76
+
expectedMessage: "msg: Cached a failed query, normalized query: tes t query , range seconds: 100, updating cache for error: Adding error with query that has whitespace and tabs Code(408). Let's see what happens.",
77
+
},
78
+
79
+
{
80
+
name: "Cacheable error code with range of 0, ensuring regex parsing is correct, and updating range length",
81
+
err: errors.New("error code( Code(408) error.)"),
82
+
query: url.Values{
83
+
"start": {"100"},
84
+
"end": {"180"},
85
+
"query": {"test_query"},
86
+
},
87
+
expectedResult: true,
88
+
expectedMessage: "msg: Cached a failed query, normalized query: test_query, range seconds: 80, updating cache for error: error code( Code(408) error.)",
89
+
},
90
+
91
+
{
92
+
name: "Successful update to range length",
93
+
err: errors.New("error code( Code(408) error.)"),
94
+
query: url.Values{
95
+
"start": {"100"},
96
+
"end": {"100"},
97
+
"query": {"test_query"},
98
+
},
99
+
expectedResult: true,
100
+
expectedMessage: "msg: Cached a failed query, normalized query: test_query, range seconds: 0, updating cache for error: error code( Code(408) error.)",
0 commit comments