Update weights requests with invalid JSON structure should return '400 Bad Request'.
| 145 | // Update weights requests with invalid JSON structure |
| 146 | // should return '400 Bad Request'. |
| 147 | TEST_F(DynamicWeightsTest, PutInvalidRequest) |
| 148 | { |
| 149 | Try<Owned<cluster::Master>> master = StartMaster(); |
| 150 | ASSERT_SOME(master); |
| 151 | |
| 152 | // Tests whether an update weights request with invalid JSON fails. |
| 153 | string badRequest = |
| 154 | "[{" |
| 155 | " \"weight\":3.2," |
| 156 | " \"role\"" |
| 157 | "}]"; |
| 158 | |
| 159 | Future<Response> response = process::http::request( |
| 160 | process::http::createRequest( |
| 161 | master.get()->pid, |
| 162 | "PUT", |
| 163 | false, |
| 164 | "weights", |
| 165 | createBasicAuthHeaders(DEFAULT_CREDENTIAL), |
| 166 | badRequest)); |
| 167 | |
| 168 | AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response); |
| 169 | |
| 170 | checkWithGetRequest(master.get()->pid, DEFAULT_CREDENTIAL); |
| 171 | |
| 172 | // Tests whether an update weights request with an invalid field fails. |
| 173 | // In this case, the correct field name should be 'role'. |
| 174 | badRequest = |
| 175 | "[{" |
| 176 | " \"weight\":3.2," |
| 177 | " \"invalidField\":\"role1\"" |
| 178 | "}]"; |
| 179 | |
| 180 | response = process::http::request( |
| 181 | process::http::createRequest( |
| 182 | master.get()->pid, |
| 183 | "PUT", |
| 184 | false, |
| 185 | "weights", |
| 186 | createBasicAuthHeaders(DEFAULT_CREDENTIAL), |
| 187 | badRequest)); |
| 188 | |
| 189 | AWAIT_EXPECT_RESPONSE_STATUS_EQ(BadRequest().status, response); |
| 190 | |
| 191 | checkWithGetRequest(master.get()->pid, DEFAULT_CREDENTIAL); |
| 192 | } |
| 193 | |
| 194 | |
| 195 | // An update weights request with zero value |
nothing calls this directly
no test coverage detected