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

getdozer / dozer / 6009657516

29 Aug 2023 08:13AM UTC coverage: 76.652% (-1.4%) from 78.07%
6009657516

push

github

web-flow
chore: Create unit tests workflow (#1910)

* chore: Update for Rust 1.72.0

Rust 1.72.0 has introduced a bunch of new lints. Here we fix them all.

`let ... else` finally gets formatted.

* chire: Create unit tests workflow

* Rename and remove useless steps

* remove env vars

* Add concurrency group

* Test unit workflow on 4 cores

* Add mysql service to unit tests

---------

Co-authored-by: chubei <914745487@qq.com>

48982 of 63902 relevant lines covered (76.65%)

48394.25 hits per line

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

81.4
/dozer-sql/src/pipeline/expression/tests/test_common.rs
1
use crate::pipeline::{projection::factory::ProjectionProcessorFactory, tests::utils::get_select};
2
use dozer_core::channels::ProcessorChannelForwarder;
3
use dozer_core::executor_operation::ProcessorOperation;
4
use dozer_core::node::ProcessorFactory;
5
use dozer_core::processor_record::ProcessorRecordStore;
6
use dozer_core::DEFAULT_PORT_HANDLE;
7
use dozer_types::chrono::{
8
    DateTime, Datelike, FixedOffset, NaiveDate, NaiveDateTime, NaiveTime, Timelike,
9
};
10
use dozer_types::rust_decimal::Decimal;
11
use dozer_types::types::Record;
12
use dozer_types::types::{Field, Schema};
13
use proptest::prelude::*;
14
use std::collections::HashMap;
15

16
struct TestChannelForwarder {
17
    operations: Vec<ProcessorOperation>,
18
}
19

20
impl ProcessorChannelForwarder for TestChannelForwarder {
21
    fn send(&mut self, op: ProcessorOperation, _port: dozer_core::node::PortHandle) {
1,158✔
22
        self.operations.push(op);
1,158✔
23
    }
1,158✔
24
}
×
25

26
pub(crate) fn run_fct(sql: &str, schema: Schema, input: Vec<Field>) -> Field {
1,159✔
27
    let record_store = ProcessorRecordStore::new().unwrap();
1,159✔
28

1,159✔
29
    let select = get_select(sql).unwrap();
1,159✔
30
    let processor_factory =
1,159✔
31
        ProjectionProcessorFactory::_new("projection_id".to_owned(), select.projection);
1,159✔
32
    processor_factory
1,159✔
33
        .get_output_schema(
1,159✔
34
            &DEFAULT_PORT_HANDLE,
1,159✔
35
            &[(DEFAULT_PORT_HANDLE, schema.clone())]
1,159✔
36
                .into_iter()
1,159✔
37
                .collect(),
1,159✔
38
        )
1,159✔
39
        .unwrap();
1,159✔
40

1,159✔
41
    let mut processor = processor_factory
1,159✔
42
        .build(
1,159✔
43
            HashMap::from([(DEFAULT_PORT_HANDLE, schema)]),
1,159✔
44
            HashMap::new(),
1,159✔
45
            &record_store,
1,159✔
46
        )
1,159✔
47
        .unwrap();
1,159✔
48

1,159✔
49
    let mut fw = TestChannelForwarder { operations: vec![] };
1,159✔
50
    let rec = Record::new(input);
1,159✔
51
    let rec = record_store.create_record(&rec).unwrap();
1,159✔
52

1,159✔
53
    let op = ProcessorOperation::Insert { new: rec };
1,159✔
54

1,159✔
55
    processor
1,159✔
56
        .process(DEFAULT_PORT_HANDLE, &record_store, op, &mut fw)
1,159✔
57
        .unwrap();
1,159✔
58

1,159✔
59
    match &fw.operations[0] {
1,159✔
60
        ProcessorOperation::Insert { new } => {
1,159✔
61
            let mut new = record_store.load_record(new).unwrap();
1,159✔
62
            new.values.remove(0)
1,159✔
63
        }
×
64
        _ => panic!("Unable to find result value"),
×
65
    }
×
66
}
1,159✔
67

68
#[derive(Debug)]
×
69
pub struct ArbitraryDecimal(pub Decimal);
70

×
71
impl Arbitrary for ArbitraryDecimal {
72
    type Parameters = ();
×
73
    type Strategy = BoxedStrategy<Self>;
74

75
    fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
18✔
76
        (i64::MIN..i64::MAX, u32::MIN..29u32)
18✔
77
            .prop_map(|(num, scale)| ArbitraryDecimal(Decimal::new(num, scale)))
18,000✔
78
            .boxed()
18✔
79
    }
18✔
80
}
×
81

×
82
#[derive(Debug)]
×
83
pub struct ArbitraryDateTime(pub DateTime<FixedOffset>);
×
84

85
impl Arbitrary for ArbitraryDateTime {
86
    type Parameters = ();
×
87
    type Strategy = BoxedStrategy<Self>;
88

89
    fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy {
4✔
90
        (
4✔
91
            NaiveDateTime::MIN.year()..NaiveDateTime::MAX.year(),
4✔
92
            1..13u32,
4✔
93
            1..32u32,
4✔
94
            0..NaiveDateTime::MAX.second(),
4✔
95
            0..NaiveDateTime::MAX.nanosecond(),
4✔
96
        )
4✔
97
            .prop_map(|(year, month, day, secs, nano)| {
4,000✔
98
                let timezone_east = FixedOffset::east_opt(8 * 60 * 60).unwrap();
4,000✔
99
                let date = NaiveDate::from_ymd_opt(year, month, day);
4,000✔
100
                // Some dates are not able to created caused by leap in February with day larger than 28 or 29
4,000✔
101
                if date.is_none() {
4,000✔
102
                    return ArbitraryDateTime(DateTime::default());
96✔
103
                }
3,904✔
104
                let time = NaiveTime::from_num_seconds_from_midnight_opt(secs, nano).unwrap();
3,904✔
105
                let datetime = DateTime::<FixedOffset>::from_local(
3,904✔
106
                    NaiveDateTime::new(date.unwrap(), time),
3,904✔
107
                    timezone_east,
3,904✔
108
                );
3,904✔
109
                ArbitraryDateTime(datetime)
3,904✔
110
            })
4,000✔
111
            .boxed()
4✔
112
    }
4✔
113
}
×
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