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

Fix tests for rustc 1.82-beta #561

Merged
merged 1 commit into from
Sep 8, 2024
Merged
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
31 changes: 19 additions & 12 deletions src/ice/candidate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -566,18 +566,25 @@ mod tests {
let socket_addr = "1.2.3.4:9876".parse().unwrap();
let mut candidate = Candidate::host(socket_addr, Protocol::Udp).unwrap();
assert_eq!(
serde_json::to_string(&candidate).unwrap(),
r#"{"candidate":"candidate:fffeff7ea7250f6f639706d6 1 udp 2130706175 1.2.3.4 9876 typ host","sdpMid":null,"sdpMLineIndex":0,"usernameFragment":null}"#
no_hash(serde_json::to_string(&candidate).unwrap()),
r#"{"candidate":"candidate:--- 1 udp 2130706175 1.2.3.4 9876 typ host","sdpMid":null,"sdpMLineIndex":0,"usernameFragment":null}"#
);

// Add a username fragment
candidate.ufrag = Some("ufrag".to_string());
assert_eq!(
serde_json::to_string(&candidate).unwrap(),
r#"{"candidate":"candidate:fffeff7ea7250f6f639706d6 1 udp 2130706175 1.2.3.4 9876 typ host ufrag ufrag","sdpMid":null,"sdpMLineIndex":0,"usernameFragment":"ufrag"}"#
no_hash(serde_json::to_string(&candidate).unwrap()),
r#"{"candidate":"candidate:--- 1 udp 2130706175 1.2.3.4 9876 typ host ufrag ufrag","sdpMid":null,"sdpMLineIndex":0,"usernameFragment":"ufrag"}"#
);
}

fn no_hash(mut s: String) -> String {
let f = s.find("candidate:").unwrap();
let t = s.find(" 1 ").unwrap();
s.replace_range((f + 10)..t, "---");
s
}

#[test]
fn deserialize() {
let json = r#"{"candidate":"candidate:12044049749558888150 1 udp 2130706175 1.2.3.4 9876 typ host ufrag ufrag","sdpMid":"ignored","sdpMLineIndex":123,"usernameFragment":"ufrag"}"#;
Expand All @@ -598,25 +605,25 @@ mod tests {
let socket_addr = "1.2.3.4:9876".parse().unwrap();
let mut candidate = Candidate::host(socket_addr, Protocol::Udp).unwrap();
assert_eq!(
candidate.to_string(),
"candidate:fffeff7ea7250f6f639706d6 1 udp 2130706175 1.2.3.4 9876 typ host"
no_hash(candidate.to_string()),
"candidate:--- 1 udp 2130706175 1.2.3.4 9876 typ host"
);

candidate.ufrag = Some("ufrag".into());
assert_eq!(
candidate.to_string(),
"candidate:fffeff7ea7250f6f639706d6 1 udp 2130706175 1.2.3.4 9876 typ host ufrag ufrag"
no_hash(candidate.to_string()),
"candidate:--- 1 udp 2130706175 1.2.3.4 9876 typ host ufrag ufrag"
);

candidate.raddr = Some("5.5.5.5:5555".parse().unwrap());
assert_eq!(
candidate.to_string(),
"candidate:fffeff7e5e895846293d220a 1 udp 2130706175 1.2.3.4 9876 typ host raddr 5.5.5.5 rport 5555 ufrag ufrag");
no_hash(candidate.to_string()),
"candidate:--- 1 udp 2130706175 1.2.3.4 9876 typ host raddr 5.5.5.5 rport 5555 ufrag ufrag");

let candidate = Candidate::relayed(socket_addr, Protocol::SslTcp).unwrap();
assert_eq!(
candidate.to_string(),
"candidate:fffeff006014aaa376aa19b 1 ssltcp 16776959 1.2.3.4 9876 typ relay"
no_hash(candidate.to_string()),
"candidate:--- 1 ssltcp 16776959 1.2.3.4 9876 typ relay"
);
}

Expand Down
Loading