Skip to content

Commit

Permalink
Merge branch 'main' of github.com:meshtastic/rust into ble-setup
Browse files Browse the repository at this point in the history
  • Loading branch information
ajmcquilkin committed Jan 19, 2024
2 parents 7ddeba1 + 60e57ea commit 1c27805
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 13 deletions.
13 changes: 13 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# These are supported funding model platforms

github: ajmcquilkin # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2]
patreon: # Replace with a single Patreon username
open_collective: # Replace with a single Open Collective username
ko_fi: # Replace with a single Ko-fi username
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
liberapay: # Replace with a single Liberapay username
issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
34 changes: 34 additions & 0 deletions .github/workflows/testing.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: "Testing Suite"
on: [push, pull_request]

jobs:
unit-test:
permissions:
contents: write
strategy:
matrix:
platform: [macos-latest, ubuntu-20.04, windows-latest]

runs-on: ${{ matrix.platform }}
steps:
- uses: actions/checkout@v3
- run: git submodule update --init

- name: Initialize Rust Cache
uses: actions/cache@v2
with:
path: |
~/target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}

- name: Setup pnpm
uses: pnpm/action-setup@v2
with:
version: 8

- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable

- name: Run test suite
working-directory: ./
run: cargo test
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ license = "GPL-3.0"
version = "0.1.5"
edition = "2021"

[lib]
doctest = false

[features]
default = ["serde"]

Expand Down
6 changes: 3 additions & 3 deletions src/connections/stream_buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ mod tests {
// Attempt to decode packet

let mut buffer = StreamBuffer::new(mock_tx);
buffer.process_incoming_bytes(encoded_packet.data().into());
buffer.process_incoming_bytes(encoded_packet.unwrap().data().into());

assert_eq!(mock_rx.recv().await.unwrap(), packet);
assert_eq!(buffer.buffer.len(), 0);
Expand All @@ -295,8 +295,8 @@ mod tests {
let (packet1, packet_data1) = mock_encoded_from_radio_packet(1, payload_variant1);
let (packet2, packet_data2) = mock_encoded_from_radio_packet(2, payload_variant2);

let encoded_packet1 = format_data_packet(packet_data1.into());
let encoded_packet2 = format_data_packet(packet_data2.into());
let encoded_packet1 = format_data_packet(packet_data1.into()).unwrap();
let encoded_packet2 = format_data_packet(packet_data2.into()).unwrap();

let (mock_tx, mut mock_rx) = unbounded_channel::<protobufs::FromRadio>();

Expand Down
18 changes: 8 additions & 10 deletions src/utils_internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -439,7 +439,7 @@ mod tests {
let data = vec![];
let serial_data = format_data_packet(data.into());

assert_eq!(serial_data.data(), Some(vec![0x94, 0xc3, 0x00, 0x00]));
assert_eq!(serial_data.unwrap().data(), vec![0x94, 0xc3, 0x00, 0x00]);
}

#[test]
Expand All @@ -448,8 +448,8 @@ mod tests {
let serial_data = format_data_packet(data.into());

assert_eq!(
serial_data.data(),
Some(vec![0x94, 0xc3, 0x00, 0x03, 0x00, 0xff, 0x88])
serial_data.unwrap().data(),
vec![0x94, 0xc3, 0x00, 0x03, 0x00, 0xff, 0x88]
);
}

Expand All @@ -458,19 +458,17 @@ mod tests {
let data = vec![0x00; 0x100];
let serial_data = format_data_packet(data.into());

assert_eq!(serial_data.data()[..4], Some(vec![0x94, 0xc3, 0x01, 0x00]));
assert_eq!(
serial_data.unwrap().data()[..4],
vec![0x94, 0xc3, 0x01, 0x00]
);
}

#[test]
fn invalid_too_large_packet() {
let data = vec![0x00; 0x10000];
let serial_data = format_data_packet(data.into());

assert_eq!(
serial_data,
Err(Error::InvalidaDataSize {
data_length: 0x10000
})
);
assert_eq!(serial_data.is_err(), true);
}
}

0 comments on commit 1c27805

Please sign in to comment.