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

getdozer / dozer / 4007820649

pending completion
4007820649

Pull #734

github

GitHub
Merge b71e66da1 into 6c0ac2b2c
Pull Request #734: Bump ahash from 0.8.2 to 0.8.3

23507 of 35166 relevant lines covered (66.85%)

40241.5 hits per line

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

96.3
/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
use std::sync::Arc;
8

9
use dozer_cache::cache::{Cache, CacheOptions, LmdbCache};
10

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

×
62
pub fn get_endpoint() -> ApiEndpoint {
23✔
63
    ApiEndpoint {
23✔
64
        name: "films".to_string(),
23✔
65
        path: "/films".to_string(),
23✔
66
        sql: "select film_id, description, rental_rate, release_year, updated_at from film where 1=1;"
23✔
67
            .to_string(),
23✔
68
        index: Some(ApiIndex {
23✔
69
            primary_key: vec!["film_id".to_string()],
23✔
70
        }),
23✔
71
        ..Default::default()
23✔
72
    }
23✔
73
}
23✔
74

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

×
93
    for film_id in 1..=50 {
1,173✔
94
        result.push(json!({
1,150✔
95
            "film_id": film_id,
1,150✔
96
            "description": format!("Film {}", film_id),
1,150✔
97
            "rental_rate": null,
1,150✔
98
            "release_year": 2006,
1,150✔
99
            "updated_at": null
1,150✔
100
        }));
1,150✔
101
    }
1,150✔
102
    result
23✔
103
}
23✔
104

×
105
pub fn initialize_cache(
22✔
106
    schema_name: &str,
22✔
107
    schema: Option<(dozer_types::types::Schema, Vec<IndexDefinition>)>,
22✔
108
) -> Arc<LmdbCache> {
22✔
109
    let cache = Arc::new(LmdbCache::new(CacheOptions::default()).unwrap());
22✔
110
    let (schema, secondary_indexes) = schema.unwrap_or_else(get_schema);
22✔
111
    cache
22✔
112
        .insert_schema(schema_name, &schema, &secondary_indexes)
22✔
113
        .unwrap();
22✔
114
    let records = get_sample_records(schema);
22✔
115
    for record in records {
1,166✔
116
        cache.insert(&record).unwrap();
1,144✔
117
    }
1,144✔
118
    cache
22✔
119
}
22✔
120

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