Initial unit tests for Trustee interaction#53
Conversation
d7042e0 to
e93dc43
Compare
| async fn test_generate_att_policy_success() { | ||
| let ns = "test".to_string(); | ||
| let client = MockClient::new(StatusCode::OK, ConfigMap::default(), ns).into_client(); | ||
| let clos = |_: &_| Ok(ConfigMap::default()); |
There was a problem hiding this comment.
nit: can you create a macro for the cases we don't use any input, it will be a bit easier to read the code:
macro_rules! return_config_map {
(ok) => {
|_: &_| Ok(ConfigMap::default())
};
(err, $err:expr) => {
|_: &_| Err::<ConfigMap, _>($err)
};
}
let clos_ok = return_config_map!(ok);
let clos_err = return_config_map!(err, StatusCode::CONFLICT);There was a problem hiding this comment.
had one but dropped it again. checking URIs & methods now, and with that there would be one single use for the Ok case and zero for the Err case.
|
@Jakob-Naucke one question, you are implementing a closure which return a single object for all the type of requests. I'm wondering if we should distinguish the type of request. IOW, I might want to use the mocking client for Another functionalities we might require in the future is the ability to specify how many times you want to return that object. For example, in a retry loop we might just want to return it only once and then changing behavior. It can be useful for example to test the recovery from an error, you return first and error and then the correct object. |
|
it already looks very promising, thanks! I will do a second pass later |
hmm, already with this patch you could match on the method in the same way that e.g.
ayy, state. I suppose the |
yes, but you aren't checking that. It could be any method called and you return that with the mock.
Yes, the comment wasn't for now |
Sorry, I still don't understand what you're going for. You could do e.g. let clos = move |req: &Option<Request<_>>| match req {
Some(r) if r.method() == Method::PATCH => Ok(some_config_map.clone()),
…what is it instead that you want to be able to do? |
a62f869 to
ace593d
Compare
Signed-off-by: Jakob Naucke <jnaucke@redhat.com>
instead as subroutine for better testability Signed-off-by: Jakob Naucke <jnaucke@redhat.com>
Signed-off-by: Alice Frosi <afrosi@redhat.com> Co-authored-by: Jakob Naucke <jnaucke@redhat.com>
- `test_generate_att_policy_success`: Verifies the function returns `Ok(())` on a successful API response (200 OK). - `test_generate_att_policy_already_exists`: Verifies the function correctly handles a 409 Conflict and returns `Ok(())`, confirming idempotency. - `test_generate_att_policy_error`: Verifies server errors are returned correctly. Signed-off-by: Dehan Meng <demeng@redhat.com> Co-authored-by: Alice Frosi <afrosi@redhat.com> Co-authored-by: Jakob Naucke <jnaucke@redhat.com>
- `test_get_image_pcrs_success`: Verifies that a valid JSON string in a ConfigMap is correctly deserialized into the `ImagePcrs` struct. - `test_get_image_pcrs_no_data`: Ensures an error is returned when the ConfigMap's `data` field is missing. - `test_get_image_pcrs_no_file`: Ensures an error is returned when the ConfigMap's `data` field is empty. - `test_get_image_pcrs_invalid_json`: Confirms that an error is propagated when the data contains an invalid JSON string. Signed-off-by: Dehan Meng <demeng@redhat.com> Co-authored-by: Jakob Naucke <jnaucke@redhat.com>
A sanity check to validate that `generate_luks_key` runs without errors and returns a key of the expected 32-byte length. Signed-off-by: Dehan Meng <demeng@redhat.com> Co-authored-by: Jakob Naucke <jnaucke@redhat.com>
Instrument MockClient to respond with a closure on a result of request body and status code. Signed-off-by: Jakob Naucke <jnaucke@redhat.com>
Success, missing PCR ConfigMap, missing Trustee ConfigMap, missing Trustee data, missing RV file Signed-off-by: Jakob Naucke <jnaucke@redhat.com>
Signed-off-by: Jakob Naucke <jnaucke@redhat.com>
for generate_{secret,trustee_data,kbs_{service,deployment}}
Signed-off-by: Jakob Naucke <jnaucke@redhat.com>
Signed-off-by: Jakob Naucke <jnaucke@redhat.com>
Signed-off-by: Jakob Naucke <jnaucke@redhat.com>
ace593d to
293c368
Compare
As discussed offline, this is exactly what I want. The issue was that the test didn't include the specification of the method we were testing against |
|
Very nice, thanks Jakob for the work! Looks great! |
Respinning #34. Attempts to supersede #39 + #20.
e: contains some minimally-invasive refactorings for better testability in separate commits