Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean code #20

Merged
merged 5 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 1 addition & 22 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,6 @@ on:
name: Build

jobs:
check:
name: Check
runs-on: ubuntu-latest
steps:
- name: Checkout sources
uses: actions/checkout@v4

- name: Run cargo check
run: cargo check

test:
name: Test Suite
runs-on: ubuntu-latest
Expand Down Expand Up @@ -44,7 +34,7 @@ jobs:
path: target/nextest/ci/*.xml
reporter: java-junit
max-annotations: 50
name: Unit Tests
name: Test Suite Summary
lints:
name: Lints
runs-on: ubuntu-latest
Expand All @@ -65,8 +55,6 @@ jobs:
CARGO_TERM_COLOR: always
steps:
- uses: actions/checkout@v4
- name: Update Rust
run: rustup update stable
- uses: taiki-e/install-action@cargo-llvm-cov
- uses: taiki-e/install-action@nextest
- name: Generate code coverage
Expand All @@ -76,12 +64,3 @@ jobs:
with:
files: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
# this is needed by zgosalvez/github-actions-report-lcov
- name: Setup LCOV
uses: hrishikesh-kadam/setup-lcov@v1
- name: Report code coverage
uses: zgosalvez/github-actions-report-lcov@v4
with:
coverage-files: lcov.info
artifact-name: code-coverage-report
update-comment: true
8 changes: 5 additions & 3 deletions src/mitaffald/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use self::settings::{AddressId, TraditionalAddress};

pub async fn get_containers(config: AffaldVarmeConfig) -> Result<Vec<Container>, String> {
let response = fetch_remote_response(config).await?;
let response = fetch_collection_plan(config).await?;

if !response.status().is_success() {
return Err(format!("Unexpected status code: {:?}", response.status()));
Expand Down Expand Up @@ -53,7 +53,7 @@
fractions: Vec<String>,
}

async fn fetch_remote_response(config: AffaldVarmeConfig) -> Result<reqwest::Response, String> {
async fn fetch_collection_plan(config: AffaldVarmeConfig) -> Result<reqwest::Response, String> {
let remote_url = build_remote_url(config).await?;

reqwest::get(remote_url)
Expand Down Expand Up @@ -105,7 +105,9 @@
.and_then(|x| x.as_str())
.map(|x| AddressId { id: x.to_owned() })
})
.ok_or_else(|| "Address not found".to_string())
.ok_or_else(|| {
"Address not found or multiple addresses matched the search criteria".to_string()

Check warning on line 109 in src/mitaffald/mod.rs

View check run for this annotation

Codecov / codecov/patch

src/mitaffald/mod.rs#L109

Added line #L109 was not covered by tests
})
}

#[derive(Debug, PartialEq)]
Expand Down
12 changes: 6 additions & 6 deletions tests/full_flow_insta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ async fn smoke_test_insta() {
},
};

let mut collecting_client = CollectingClient::new();
collecting_client.start(&settings.mqtt);
let mut home_assistant = CollectingClient::new();
home_assistant.start(&settings.mqtt);

let sync_result = sync_data(settings).await;

Expand All @@ -58,17 +58,17 @@ async fn smoke_test_insta() {
sync_result.err()
);

let collect_result = collecting_client.wait_for_messages(20, Duration::from_secs(60));
let ha_messages_result = home_assistant.wait_for_messages(20, Duration::from_secs(60));

assert!(
collect_result.is_ok(),
ha_messages_result.is_ok(),
"Error waiting for messages: {}",
collect_result.unwrap_err()
ha_messages_result.unwrap_err()
);

mit_affald_server.assert_async().await;

let actual = actual(collect_result.unwrap());
let actual = actual(ha_messages_result.unwrap());

insta::with_settings!({
filters=>vec![
Expand Down