@@ -150,6 +150,32 @@ func Test_PostConfig_CreatesConfig(t *testing.T) {
150
150
assert .Equal (t , config , result .Config )
151
151
}
152
152
153
+ // Posting an invalid config when there's none set returns an error and leaves the config unset.
154
+ func Test_PostConfig_InvalidNewConfig (t * testing.T ) {
155
+ setup (t )
156
+ defer cleanup (t )
157
+
158
+ userID := makeUserID ()
159
+ invalidConfig := map [string ]string {
160
+ "some.rules" : "invalid config" ,
161
+ }
162
+ updateRequest := configUpdateRequest {
163
+ OldConfig : nil ,
164
+ NewConfig : invalidConfig ,
165
+ }
166
+ b , err := json .Marshal (updateRequest )
167
+ require .NoError (t , err )
168
+ reader := bytes .NewReader (b )
169
+ {
170
+ w := requestAsUser (t , userID , "POST" , endpoint , reader )
171
+ require .Equal (t , http .StatusBadRequest , w .Code )
172
+ }
173
+ {
174
+ w := requestAsUser (t , userID , "GET" , endpoint , nil )
175
+ require .Equal (t , http .StatusNotFound , w .Code )
176
+ }
177
+ }
178
+
153
179
// Posting to a configuration sets it so that you can get it again.
154
180
func Test_PostConfig_UpdatesConfig (t * testing.T ) {
155
181
setup (t )
@@ -164,6 +190,32 @@ func Test_PostConfig_UpdatesConfig(t *testing.T) {
164
190
assert .Equal (t , config2 , view2 .Config )
165
191
}
166
192
193
+ // Posting an invalid config when there's one already set returns an error and leaves the config as is.
194
+ func Test_PostConfig_InvalidChangedConfig (t * testing.T ) {
195
+ setup (t )
196
+ defer cleanup (t )
197
+
198
+ userID := makeUserID ()
199
+ config := makeRulerConfig ()
200
+ post (t , userID , nil , config )
201
+ invalidConfig := map [string ]string {
202
+ "some.rules" : "invalid config" ,
203
+ }
204
+ updateRequest := configUpdateRequest {
205
+ OldConfig : nil ,
206
+ NewConfig : invalidConfig ,
207
+ }
208
+ b , err := json .Marshal (updateRequest )
209
+ require .NoError (t , err )
210
+ reader := bytes .NewReader (b )
211
+ {
212
+ w := requestAsUser (t , userID , "POST" , endpoint , reader )
213
+ require .Equal (t , http .StatusBadRequest , w .Code )
214
+ }
215
+ result := get (t , userID )
216
+ assert .Equal (t , config , result .Config )
217
+ }
218
+
167
219
// Different users can have different configurations.
168
220
func Test_PostConfig_MultipleUsers (t * testing.T ) {
169
221
setup (t )
@@ -241,6 +293,5 @@ func Test_GetConfigs_IncludesNewerConfigsAndExcludesOlder(t *testing.T) {
241
293
}
242
294
243
295
// Test user w/ only alertmanager config doesn't show up in getallconfigs
244
- // Test posting invalid config
245
296
// Test setting ruler config doesn't change alertmanager config
246
297
// Test setting alertmanager config doesn't change ruler config
0 commit comments