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

getdozer / dozer / 4370280743

pending completion
4370280743

push

github

GitHub
Bump async-trait from 0.1.65 to 0.1.66 (#1179)

27808 of 38702 relevant lines covered (71.85%)

25323.55 hits per line

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

96.38
/dozer-api/src/test_utils.rs
1
use dozer_types::serde_json::{json, Value};
2
use dozer_types::types::{Field, Record, SourceDefinition};
3
use dozer_types::{
4
    models::api_endpoint::{ApiEndpoint, ApiIndex},
5
    types::{FieldDefinition, FieldType, IndexDefinition, Schema, SchemaIdentifier},
6
};
7

8
use dozer_cache::cache::{CacheManager, LmdbCacheManager, RecordWithId};
9

10
pub fn get_schema() -> (Schema, Vec<IndexDefinition>) {
23✔
11
    let fields = vec![
23✔
12
        FieldDefinition {
23✔
13
            name: "film_id".to_string(),
23✔
14
            typ: FieldType::UInt,
23✔
15
            nullable: false,
23✔
16
            source: SourceDefinition::Dynamic,
23✔
17
        },
23✔
18
        FieldDefinition {
23✔
19
            name: "description".to_string(),
23✔
20
            typ: FieldType::String,
23✔
21
            nullable: true,
23✔
22
            source: SourceDefinition::Dynamic,
23✔
23
        },
23✔
24
        FieldDefinition {
23✔
25
            name: "rental_rate".to_string(),
23✔
26
            typ: FieldType::Float,
23✔
27
            nullable: true,
23✔
28
            source: SourceDefinition::Dynamic,
23✔
29
        },
23✔
30
        FieldDefinition {
23✔
31
            name: "release_year".to_string(),
23✔
32
            typ: FieldType::UInt,
23✔
33
            nullable: true,
23✔
34
            source: SourceDefinition::Dynamic,
23✔
35
        },
23✔
36
        FieldDefinition {
23✔
37
            name: "updated_at".to_string(),
23✔
38
            typ: FieldType::Timestamp,
23✔
39
            nullable: true,
23✔
40
            source: SourceDefinition::Dynamic,
23✔
41
        },
23✔
42
    ];
23✔
43
    let secondary_indexes = fields
23✔
44
        .iter()
23✔
45
        .enumerate()
23✔
46
        .map(|(idx, _f)| IndexDefinition::SortedInverted(vec![idx]))
120✔
47
        .collect();
23✔
48
    (
23✔
49
        Schema {
23✔
50
            identifier: Some(SchemaIdentifier {
23✔
51
                id: 3003108387,
23✔
52
                version: 1,
23✔
53
            }),
23✔
54
            fields,
23✔
55
            primary_index: vec![0],
23✔
56
        },
23✔
57
        secondary_indexes,
23✔
58
    )
23✔
59
}
23✔
60

61
pub fn get_endpoint() -> ApiEndpoint {
23✔
62
    ApiEndpoint {
23✔
63
        name: "films".to_string(),
23✔
64
        path: "/films".to_string(),
23✔
65
        index: Some(ApiIndex {
23✔
66
            primary_key: vec!["film_id".to_string()],
23✔
67
        }),
23✔
68
        table_name: "film".to_string(),
23✔
69
    }
23✔
70
}
23✔
71

72
fn get_films() -> Vec<Value> {
20✔
73
    let mut result = vec![
20✔
74
        json!({
20✔
75
          "description": "A Amazing Panorama of a Mad Scientist And a Husband who must Meet a Woman in The Outback",
20✔
76
          "rental_rate": null,
20✔
77
          "release_year": 2006,
20✔
78
          "film_id": 268,
20✔
79
          "updated_at": null
20✔
80
        }),
20✔
81
        json!({
20✔
82
          "film_id": 524,
20✔
83
          "release_year": 2006,
20✔
84
          "rental_rate": null,
20✔
85
          "description": "A Intrepid Display of a Pastry Chef And a Cat who must Kill a A Shark in Ancient China",
20✔
86
          "updated_at": null
20✔
87
        }),
20✔
88
    ];
20✔
89

90
    for film_id in 1..=50 {
1,014✔
91
        result.push(json!({
994✔
92
            "film_id": film_id,
994✔
93
            "description": format!("Film {film_id}"),
994✔
94
            "rental_rate": null,
994✔
95
            "release_year": 2006,
994✔
96
            "updated_at": null
994✔
97
        }));
994✔
98
    }
994✔
99
    result
20✔
100
}
20✔
101

102
pub fn initialize_cache(
19✔
103
    schema_name: &str,
19✔
104
    schema: Option<(Schema, Vec<IndexDefinition>)>,
19✔
105
) -> Box<dyn CacheManager> {
19✔
106
    let cache_manager = LmdbCacheManager::new(Default::default()).unwrap();
19✔
107
    let (schema, secondary_indexes) = schema.unwrap_or_else(get_schema);
19✔
108
    let cache = cache_manager
19✔
109
        .create_cache(schema.clone(), secondary_indexes)
19✔
110
        .unwrap();
19✔
111
    let records = get_sample_records(schema);
19✔
112
    for mut record in records {
982✔
113
        cache.insert(&mut record.record).unwrap();
963✔
114
    }
963✔
115
    cache.commit().unwrap();
19✔
116

19✔
117
    cache_manager
19✔
118
        .create_alias(cache.name(), schema_name)
19✔
119
        .unwrap();
19✔
120
    Box::new(cache_manager)
19✔
121
}
19✔
122

×
123
pub fn get_sample_records(schema: Schema) -> Vec<RecordWithId> {
20✔
124
    let records_value: Vec<Value> = get_films();
20✔
125
    let mut records = vec![];
20✔
126
    for (record_index, record_str) in records_value.into_iter().enumerate() {
1,014✔
127
        let film_id = record_str["film_id"].as_u64();
1,014✔
128
        let description = record_str["description"].as_str();
1,014✔
129
        let release_year = record_str["release_year"].as_u64();
1,014✔
130
        if let (Some(film_id), Some(description), Some(release_year)) =
1,013✔
131
            (film_id, description, release_year)
1,014✔
132
        {
1,013✔
133
            let record = Record::new(
1,013✔
134
                schema.identifier,
1,013✔
135
                vec![
1,013✔
136
                    Field::UInt(film_id),
1,013✔
137
                    Field::String(description.to_string()),
1,013✔
138
                    Field::Null,
1,013✔
139
                    Field::UInt(release_year),
1,013✔
140
                    Field::Null,
1,013✔
141
                ],
1,013✔
142
                Some(1),
1,013✔
143
            );
1,013✔
144
            records.push(RecordWithId::new(record_index as _, record));
1,013✔
145
        }
1,013✔
146
    }
×
147
    records
20✔
148
}
20✔
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

© 2026 Coveralls, Inc