Skip to content

Commit

Permalink
Misc fix (#37)
Browse files Browse the repository at this point in the history
* fix cargo clippy in rust 1.61
* add unit test for my_ipv4_addrs
* ignore vscode settings
* include windows and macOS in GitHub Actions
  • Loading branch information
keepsimple1 authored Jun 25, 2022
1 parent 88aa4d7 commit 368ff5e
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@ on:

env:
CARGO_TERM_COLOR: always
RUST_BACKTRACE: 1

jobs:
build:
runs-on: ubuntu-20.04
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v2
- name: Install Rust toolchain
Expand All @@ -29,5 +34,3 @@ jobs:
run: cargo clippy -- -D warnings
- name: Run tests
run: cargo test
- name: Run Clippy
run: cargo clippy
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# IntelliJ IDEA
/.idea/

# Visual Studio Code
/.vscode/

# Generated by Cargo
# will have compiled files and executables
/target/
Expand Down
28 changes: 19 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -766,7 +766,7 @@ impl Zeroconf {
debug!("Adding subdomain {}", sub);
out.add_answer_at_time(
Box::new(DnsPointer::new(
&sub,
sub,
TYPE_PTR,
CLASS_IN,
info.other_ttl,
Expand Down Expand Up @@ -832,7 +832,7 @@ impl Zeroconf {
debug!("Adding subdomain {}", sub);
out.add_answer_at_time(
Box::new(DnsPointer::new(
&sub,
sub,
TYPE_PTR,
CLASS_IN,
0,
Expand Down Expand Up @@ -1129,11 +1129,7 @@ impl Zeroconf {
Err(e) => error!("failed to send service info: {}", e),
}
}
let sub_query = info
.sub_domain
.as_ref()
.map(|s| self.queriers.get(s))
.flatten();
let sub_query = info.sub_domain.as_ref().and_then(|s| self.queriers.get(s));
let query = self.queriers.get(&info.ty_domain);
match (sub_query, query) {
(Some(sub_listener), Some(listener)) => {
Expand Down Expand Up @@ -1772,7 +1768,7 @@ impl DnsOutgoing {
if let Some(sub) = &service.sub_domain {
debug!("Adding subdomain {}", sub);
self.add_additional_answer(Box::new(DnsPointer::new(
&sub,
sub,
TYPE_PTR,
CLASS_IN,
service.other_ttl,
Expand Down Expand Up @@ -2750,7 +2746,7 @@ fn call_listener(
mod tests {
use std::collections::HashMap;

use crate::{decode_txt, encode_txt};
use crate::{decode_txt, encode_txt, my_ipv4_addrs};

#[test]
fn test_txt_encode_decode() {
Expand All @@ -2770,4 +2766,18 @@ mod tests {
let decoded = decode_txt(&encoded);
assert_eq!(map, decoded);
}

#[test]
fn test_my_ipv4_addrs() {
let addrs = my_ipv4_addrs();

// The test host should have at least one IPv4 addr.
assert!(!addrs.is_empty());

// Verify the address attributes.
for addr in addrs {
assert!(!addr.is_loopback());
assert!(!addr.is_multicast());
}
}
}

0 comments on commit 368ff5e

Please sign in to comment.