MCPcopy Index your code
hub / github.com/cortexproject/cortex / Test_Proxy_RequestsForwarding

Function Test_Proxy_RequestsForwarding

tools/querytee/proxy_test.go:35–186  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

33}
34
35func Test_Proxy_RequestsForwarding(t *testing.T) {
36 const (
37 querySingleMetric1 = `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"cortex_build_info"},"value":[1583320883,"1"]}]}}`
38 querySingleMetric2 = `{"status":"success","data":{"resultType":"vector","result":[{"metric":{"__name__":"cortex_build_info"},"value":[1583320883,"2"]}]}}`
39 )
40
41 type mockedBackend struct {
42 pathPrefix string
43 handler http.HandlerFunc
44 }
45
46 tests := map[string]struct {
47 backends []mockedBackend
48 preferredBackendIdx int
49 expectedStatus int
50 expectedRes string
51 }{
52 "one backend returning 2xx": {
53 backends: []mockedBackend{
54 {handler: mockQueryResponse("/api/v1/query", 200, querySingleMetric1)},
55 },
56 expectedStatus: 200,
57 expectedRes: querySingleMetric1,
58 },
59 "one backend returning 5xx": {
60 backends: []mockedBackend{
61 {handler: mockQueryResponse("/api/v1/query", 500, "")},
62 },
63 expectedStatus: 500,
64 expectedRes: "",
65 },
66 "two backends without path prefix": {
67 backends: []mockedBackend{
68 {handler: mockQueryResponse("/api/v1/query", 200, querySingleMetric1)},
69 {handler: mockQueryResponse("/api/v1/query", 200, querySingleMetric2)},
70 },
71 preferredBackendIdx: 0,
72 expectedStatus: 200,
73 expectedRes: querySingleMetric1,
74 },
75 "two backends with the same path prefix": {
76 backends: []mockedBackend{
77 {
78 pathPrefix: "/api/prom",
79 handler: mockQueryResponse("/api/prom/api/v1/query", 200, querySingleMetric1),
80 },
81 {
82 pathPrefix: "/api/prom",
83 handler: mockQueryResponse("/api/prom/api/v1/query", 200, querySingleMetric2),
84 },
85 },
86 preferredBackendIdx: 0,
87 expectedStatus: 200,
88 expectedRes: querySingleMetric1,
89 },
90 "two backends with different path prefix": {
91 backends: []mockedBackend{
92 {

Callers

nothing calls this directly

Calls 10

StopMethod · 0.95
StartMethod · 0.95
EndpointMethod · 0.95
mockQueryResponseFunction · 0.85
NewProxyFunction · 0.85
JoinMethod · 0.80
RunMethod · 0.65
CloseMethod · 0.65
GetMethod · 0.65
EqualMethod · 0.65

Tested by

no test coverage detected