@@ -63,27 +63,66 @@ func TestDistributorRingHandler(t *testing.T) {
63
63
}
64
64
65
65
func TestRequestParserWrapping (t * testing.T ) {
66
- limits := & validation.Limits {}
67
- flagext .DefaultValues (limits )
68
- limits .RejectOldSamples = false
69
- distributors , _ := prepare (t , 1 , 3 , limits , nil )
66
+ t .Run ("it calls the parser wrapper if there is one" , func (t * testing.T ) {
67
+ limits := & validation.Limits {}
68
+ flagext .DefaultValues (limits )
69
+ limits .RejectOldSamples = false
70
+ distributors , _ := prepare (t , 1 , 3 , limits , nil )
70
71
71
- var called bool
72
- distributors [0 ].RequestParserWrapper = func (requestParser push.RequestParser ) push.RequestParser {
73
- called = true
74
- return requestParser
75
- }
72
+ var called bool
73
+ distributors [0 ].RequestParserWrapper = func (requestParser push.RequestParser ) push.RequestParser {
74
+ called = true
75
+ return requestParser
76
+ }
77
+
78
+ ctx := user .InjectOrgID (context .Background (), "test-user" )
79
+ req , err := http .NewRequestWithContext (ctx , http .MethodPost , "fake-path" , nil )
80
+ require .NoError (t , err )
81
+
82
+ rec := httptest .NewRecorder ()
83
+ distributors [0 ].pushHandler (rec , req , newFakeParser ().parseRequest , push .HTTPError )
76
84
77
- ctx := user .InjectOrgID (context .Background (), "test-user" )
78
- req , err := http .NewRequestWithContext (ctx , http .MethodPost , "fake-path" , nil )
79
- require .NoError (t , err )
85
+ // unprocessable code because there are no streams in the request.
86
+ require .Equal (t , http .StatusUnprocessableEntity , rec .Code )
87
+ require .True (t , called )
88
+ })
89
+
90
+ t .Run ("it returns 204 when the parser wrapper filteres all log lines" , func (t * testing.T ) {
91
+ limits := & validation.Limits {}
92
+ flagext .DefaultValues (limits )
93
+ limits .RejectOldSamples = false
94
+ distributors , _ := prepare (t , 1 , 3 , limits , nil )
80
95
81
- distributors [0 ].pushHandler (httptest .NewRecorder (), req , stubParser , push .HTTPError )
96
+ var called bool
97
+ distributors [0 ].RequestParserWrapper = func (requestParser push.RequestParser ) push.RequestParser {
98
+ called = true
99
+ return requestParser
100
+ }
101
+
102
+ ctx := user .InjectOrgID (context .Background (), "test-user" )
103
+ req , err := http .NewRequestWithContext (ctx , http .MethodPost , "fake-path" , nil )
104
+ require .NoError (t , err )
105
+
106
+ parser := newFakeParser ()
107
+ parser .parseErr = push .ErrAllLogsFiltered
108
+
109
+ rec := httptest .NewRecorder ()
110
+ distributors [0 ].pushHandler (rec , req , parser .parseRequest , push .HTTPError )
111
+
112
+ require .True (t , called )
113
+ require .Equal (t , http .StatusNoContent , rec .Code )
114
+ })
115
+ }
116
+
117
+ type fakeParser struct {
118
+ parseErr error
119
+ }
82
120
83
- require .True (t , called )
121
+ func newFakeParser () * fakeParser {
122
+ return & fakeParser {}
84
123
}
85
124
86
- func stubParser (
125
+ func ( p * fakeParser ) parseRequest (
87
126
_ string ,
88
127
_ * http.Request ,
89
128
_ push.TenantsRetention ,
@@ -92,5 +131,5 @@ func stubParser(
92
131
_ bool ,
93
132
_ log.Logger ,
94
133
) (* logproto.PushRequest , * push.Stats , error ) {
95
- return & logproto.PushRequest {}, & push.Stats {}, nil
134
+ return & logproto.PushRequest {}, & push.Stats {}, p . parseErr
96
135
}
0 commit comments