Repository: meilisearch/meilisearch
File: crates/meilisearch/tests/index/get_index.rs (Rust)

Code before:
    assert_eq!(response.as_object().unwrap().len(), 4);
}

#[actix_rt::test]
async fn error_get_unexisting_index() {
    let index = shared_does_not_exists_index().await;

    let (response, code) = index.get().await;

    let expected_response = json!({
        "message": "Index `DOES_NOT_EXISTS` not found.",
        "code": "index_not_found",
        "type": "invalid_request",
        "link": "https://docs.meilisearch.com/errors#index_not_found"
    });

    assert_eq!(response, expected_response);
    assert_eq!(code, 404);
}

#[actix_rt::test]
async fn no_index_return_empty_list() {
    let server = Server::new_shared();
    let (response, code) = server.list_indexes(None, None).await;
    assert_eq!(code, 200);
    assert!(response["results"].is_array());
    assert!(response["results"].as_array().unwrap().is_empty());
}

#[actix_rt::test]
async fn list_multiple_indexes() {
    let server = Server::new_shared();

    let index_without_key = server.unique_index();
    let (response_without_key, _status_code) = index_without_key.create(None).await;

    let index_with_key = server.unique_index();
    let (response_with_key, _status_code) = index_with_key.create(Some("key")).await;

    index_without_key.wait_task(response_without_key.uid()).await.succeeded();
    index_with_key.wait_task(response_with_key.uid()).await.succeeded();

    let (response, code) = server.list_indexes(None, None).await;
    assert_eq!(code, 200);
    assert!(response["results"].is_array());
    let arr = response["results"].as_array().unwrap();
    assert_eq!(arr.len(), 2);
    assert!(arr.iter().any(|entry| entry["uid"] == index_without_key.uid && entry["primaryKey"] == Value::Null));
    assert!(arr.iter().any(|entry| entry["uid"] == index_with_key.uid && entry["primaryKey"] == "key"));
}


Review comment (performance):
right below this line there is this one:
```
assert!(response["results"].as_array().unwrap().is_empty());
```

And it will be flaky depending on whether it's executed with another test that creates an index or if it's alone.

For this specific test, since we're looking at the global `list_indexes` route that may be modified by all the tests at the same time, I think we prefer to keep this test slow and not use a shared server 🤔 
Or we should remove the next assert, but then we have no test ensuring we can call list index on an empty instance, so I'm more in favor of letting this test be as it is currently.

Code after:
    assert_eq!(response.as_object().unwrap().len(), 4);
}

#[actix_rt::test]
async fn error_get_unexisting_index() {
    let index = shared_does_not_exists_index().await;

    let (response, code) = index.get().await;

    let expected_response = json!({
        "message": "Index `DOES_NOT_EXISTS` not found.",
        "code": "index_not_found",
        "type": "invalid_request",
        "link": "https://docs.meilisearch.com/errors#index_not_found"
    });

    assert_eq!(response, expected_response);
    assert_eq!(code, 404);
}

#[actix_rt::test]
async fn no_index_return_empty_list() {
    let server = Server::new().await;
    let (response, code) = server.list_indexes(None, None).await;
    assert_eq!(code, 200);
    assert!(response["results"].is_array());
    assert!(response["results"].as_array().unwrap().is_empty());
}

#[actix_rt::test]
async fn list_multiple_indexes() {
    let server = Server::new_shared();

    let index_without_key = server.unique_index();
    let (response_without_key, _status_code) = index_without_key.create(None).await;

    let index_with_key = server.unique_index();
    let (response_with_key, _status_code) = index_with_key.create(Some("key")).await;

    index_without_key.wait_task(response_without_key.uid()).await.succeeded();
    index_with_key.wait_task(response_with_key.uid()).await.succeeded();

    let (response, code) = server.list_indexes(None, Some(1000)).await;
    assert_eq!(code, 200);
    assert!(response["results"].is_array());
    let arr = response["results"].as_array().unwrap();
    assert!(arr.len() >= 2, "Expected at least 2 indexes.");
    assert!(arr
        .iter()
        .any(|entry| entry["uid"] == index_without_key.uid && entry["primaryKey"] == Value::Null));
    assert!(arr