Add test scenario
This commit is contained in:
parent
b7635935ba
commit
923f726bb4
44
central_backend/engine_test/test_conflict.yaml
Normal file
44
central_backend/engine_test/test_conflict.yaml
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
devices:
|
||||||
|
- id: dev1
|
||||||
|
info:
|
||||||
|
reference: A
|
||||||
|
version: 0.0.1
|
||||||
|
max_relays: 1
|
||||||
|
time_create: 1
|
||||||
|
time_update: 1
|
||||||
|
name: Dev1
|
||||||
|
description: Day1
|
||||||
|
validated: true
|
||||||
|
enabled: true
|
||||||
|
relays:
|
||||||
|
- id: dcb3fd91-bf9b-4de3-99e5-92c1c7dd72e9
|
||||||
|
name: R1
|
||||||
|
enabled: true
|
||||||
|
priority: 1
|
||||||
|
consumption: 100
|
||||||
|
minimal_uptime: 10
|
||||||
|
minimal_downtime: 10
|
||||||
|
depends_on: []
|
||||||
|
conflicts_with: []
|
||||||
|
|
||||||
|
on: true
|
||||||
|
for: 5
|
||||||
|
should_be_on: true
|
||||||
|
|
||||||
|
- id: dcb3fd91-bf9b-4de3-99e5-92c1c7dd72e8
|
||||||
|
name: R2
|
||||||
|
enabled: true
|
||||||
|
priority: 1
|
||||||
|
consumption: 100
|
||||||
|
minimal_uptime: 10
|
||||||
|
minimal_downtime: 10
|
||||||
|
depends_on: [ ]
|
||||||
|
conflicts_with: [ dcb3fd91-bf9b-4de3-99e5-92c1c7dd72e9 ]
|
||||||
|
|
||||||
|
on: false
|
||||||
|
for: 500
|
||||||
|
should_be_on: false
|
||||||
|
|
||||||
|
online: true
|
||||||
|
|
||||||
|
curr_consumption: -10000
|
@ -378,6 +378,7 @@ mod test {
|
|||||||
use crate::energy::consumption::EnergyConsumption;
|
use crate::energy::consumption::EnergyConsumption;
|
||||||
use crate::energy::engine::EnergyEngine;
|
use crate::energy::engine::EnergyEngine;
|
||||||
use crate::utils::time_utils::time_secs;
|
use crate::utils::time_utils::time_secs;
|
||||||
|
use rust_embed::Embed;
|
||||||
|
|
||||||
#[derive(serde::Deserialize)]
|
#[derive(serde::Deserialize)]
|
||||||
struct TestRelayState {
|
struct TestRelayState {
|
||||||
@ -442,22 +443,38 @@ mod test {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn run_test(conf: &str) {
|
fn run_test(name: &str, conf: &str) {
|
||||||
let (devices, mut energy_engine, consumption, states) = parse_test_config(conf);
|
let (devices, mut energy_engine, consumption, states) = parse_test_config(conf);
|
||||||
|
|
||||||
energy_engine.refresh(consumption, &devices);
|
energy_engine.refresh(consumption, &devices);
|
||||||
|
|
||||||
for d in states {
|
for (device_s, device) in states.iter().zip(&devices) {
|
||||||
for r in d.relays {
|
for (relay_s, relay) in device_s.relays.iter().zip(&device.relays) {
|
||||||
assert_eq!(energy_engine.relay_state(r.id).on, r.should_be_on);
|
let is_on = energy_engine.relay_state(relay_s.id).on;
|
||||||
|
|
||||||
|
assert_eq!(
|
||||||
|
energy_engine.relay_state(relay_s.id).on,
|
||||||
|
relay_s.should_be_on,
|
||||||
|
"For test {name} on relay {} got state {is_on} instead of {}",
|
||||||
|
relay.name,
|
||||||
|
relay_s.should_be_on
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[derive(Embed)]
|
||||||
fn test_basic_conf() {
|
#[folder = "engine_test/"]
|
||||||
run_test(include_str!("../../engine_test/test_basic_conf.yaml"))
|
struct Asset;
|
||||||
}
|
|
||||||
|
|
||||||
// TODO : test more scenarios
|
#[test]
|
||||||
|
fn test_confs() {
|
||||||
|
for file in Asset::iter() {
|
||||||
|
let content = Asset::get(&file).unwrap();
|
||||||
|
|
||||||
|
log::info!("Testing {file}");
|
||||||
|
|
||||||
|
run_test(&file, &String::from_utf8(content.data.to_vec()).unwrap())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user