• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pulibrary / bibdata / da4a9cd5-78f1-4afd-b9b1-022bf0107b90

18 Aug 2025 04:00PM UTC coverage: 92.367% (-0.2%) from 92.556%
da4a9cd5-78f1-4afd-b9b1-022bf0107b90

Pull #2859

circleci

christinach
Move config.tonl in .cargo to be consistent with the hierarchical structure
see https://doc.rust-lang.org/cargo/reference/config.html#hierarchical-structure

Co-authored-by: Jane Sandberg <sandbergja@users.noreply.github.com>
Pull Request #2859: Support format id structure

41 of 57 new or added lines in 6 files covered. (71.93%)

7 existing lines in 2 files now uncovered.

7019 of 7599 relevant lines covered (92.37%)

425.52 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

65.96
/lib/bibdata_rs/src/solr/index.rs
1
pub use super::SolrDocument;
2
use anyhow::Result;
3
use reqwest::header::CONTENT_TYPE;
4

5
pub fn index(solr_url: &str, documents: &[SolrDocument]) -> Result<()> {
1✔
6
    let client = reqwest::blocking::Client::new();
1✔
7
    let commit_url = format!("{solr_url}/update?commit=true");
1✔
8
    client
1✔
9
        .post(&commit_url)
1✔
10
        .body(serde_json::to_string(documents)?)
1✔
11
        .header(CONTENT_TYPE, "application/json")
1✔
12
        .send()?;
1✔
13
    Ok(())
1✔
14
}
1✔
15

NEW
16
pub fn index_string(solr_url: String, documents: String) -> Result<(), magnus::Error> {
×
NEW
17
    if documents.trim().is_empty() {
×
NEW
18
        return Err(magnus::Error::new(
×
NEW
19
            magnus::exception::runtime_error(),
×
NEW
20
            "No documents to index",
×
NEW
21
        ));
×
NEW
22
    }
×
NEW
23
    let document_vec: Vec<SolrDocument> = serde_json::from_str(&documents).map_err(|e| {
×
NEW
24
        magnus::Error::new(
×
NEW
25
            magnus::exception::runtime_error(),
×
NEW
26
            format!(
×
NEW
27
                "Coulld not parse documents from JSON string: {:?}, {}",
×
28
                e, documents
29
            ),
30
        )
NEW
31
    })?;
×
32
    index(&solr_url, &document_vec).expect("Failed to index documents");
×
NEW
33
    Ok(())
×
UNCOV
34
}
×
35

36
#[cfg(test)]
37
mod tests {
38
    use super::*;
39
    use crate::solr::builder::SolrDocumentBuilder;
40

41
    #[test]
42
    fn it_posts_the_document_to_solr() {
1✔
43
        let document = SolrDocumentBuilder::default()
1✔
44
            .with_other_title_display(Some(vec!["Aspen".to_string()]))
1✔
45
            .build();
1✔
46
        let mut server = mockito::Server::new();
1✔
47
        let collection = "alma-production-rebuild";
1✔
48
        let solr_mock = server
1✔
49
            .mock(
1✔
50
                "POST",
1✔
51
                format!("/solr/{}/update?commit=true", collection).as_str(),
1✔
52
            )
1✔
53
            .match_request(|request| {
1✔
54
                // Confirm that the body of the request is valid JSON with "Aspen" in the other_title_display field
55
                let request_documents: Vec<SolrDocument> =
1✔
56
                    serde_json::from_str(&request.utf8_lossy_body().unwrap()).unwrap();
1✔
57
                request_documents[0].other_title_display == Some(vec!["Aspen".to_string()])
1✔
58
            })
1✔
59
            .create();
1✔
60

61
        let solr_url = format!("{}/solr/{collection}", &server.url());
1✔
62
        index(&solr_url, &[document]).unwrap();
1✔
63

64
        solr_mock.assert();
1✔
65
    }
1✔
66
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc