meilisearch-rust icon indicating copy to clipboard operation
meilisearch-rust copied to clipboard

Check code samples automatically

Open Mubelotix opened this issue 4 years ago • 3 comments

I added a small build script that will generate a test file from code samples. The file will be located in tests/generated_from_code_samples.rs and contains 78 additional tests. This is a great way to track breaking changes in the code samples. I also made a few fixes to code samples as there was breaking changes in the past that were not updated. Use cargo test code_sample -- --test-threads=1 to run them all.

Generated test preview


#[async_test]
async fn code_sample_delete_one_document_1() {
    // Setup
    let client = Client::new("http://localhost:7700", "masterKey");
    let _ = client.delete_index("delete_one_document_1").await;
    let movies = setup_test_index(&client, "delete_one_document_1").await;
    
    // Code sample
    let progress: Progress = movies.delete_document(25684).await.unwrap();

    // Cleanup
    let _ = client.delete_index("delete_one_document_1").await;
}

#[async_test]
async fn code_sample_delete_documents_1() {
    // Setup
    let client = Client::new("http://localhost:7700", "masterKey");
    let _ = client.delete_index("delete_documents_1").await;
    let movies = setup_test_index(&client, "delete_documents_1").await;
    
    // Code sample
    let progress: Progress = movies.delete_documents(&[23488, 153738, 437035, 363869]).await.unwrap();

    // Cleanup
    let _ = client.delete_index("delete_documents_1").await;
}

// and 76 other tests like these 2

Mubelotix avatar Apr 21 '21 20:04 Mubelotix

That's a lot of tests actually. Maybe we can avoid running code samples test. A compilation check should be enough for them in most cases but I fear it would not be perfect.

Mubelotix avatar Apr 21 '21 20:04 Mubelotix

What do you think about this @curquiza? Should we run code samples or just check that they compile? Running adds a few minutes of computation on the CI.

Mubelotix avatar May 22 '21 09:05 Mubelotix

It's as you wish :) This is too much work for the Meili team to integrate into all SDKs, it means what you are doing is a huge bonus in this one 😁 So, do what you prefer since the Meili team haven't made any decision about this yet 🙂 Adding only the compilation is already a good step from my POV :)

curquiza avatar May 24 '21 11:05 curquiza

Unfortunately, this is not possible due to documentation using multiple different indexes. Closing this PR! Thanks for your contribution anyways :)

bidoubiwa avatar Aug 31 '22 14:08 bidoubiwa