Move echo_server to tests

This commit is contained in:
Alexander Heldt
2025-11-14 19:05:08 +01:00
parent a1971693ef
commit 1dcbff3e22
3 changed files with 30 additions and 25 deletions

View File

@@ -1,30 +1,5 @@
import gleam/list
import gleeunit import gleeunit
import simplifile
import tcp/echo_server
import tcp/tcp
pub fn main() -> Nil { pub fn main() -> Nil {
gleeunit.main() gleeunit.main()
} }
pub fn tcp_send_shutdown_receive_test() {
let socket_path = "/tmp/musicplayer-test.sock"
let assert Ok(_) = echo_server.new(socket_path)
let assert Ok(socket) = tcp.connect(socket_path)
let messages = ["hello, ", "world!\n"]
list.each(messages, fn(message) {
let assert Ok(_) = tcp.send(socket, message)
})
let assert Ok(_) = tcp.shutdown(socket)
let timeout_ms = 100
assert Ok("hello, world!\n") == tcp.receive(socket, timeout_ms)
// TODO find better way to always do cleanup
simplifile.delete(socket_path)
}

30
test/tcp/tcp_test.gleam Normal file
View File

@@ -0,0 +1,30 @@
import gleam/list
import gleeunit
import simplifile
import echo_server
import tcp/tcp
pub fn main() -> Nil {
gleeunit.main()
}
pub fn tcp_send_shutdown_receive_test() {
let socket_path = "/tmp/musicplayer-test.sock"
let assert Ok(_) = echo_server.new(socket_path)
let assert Ok(socket) = tcp.connect(socket_path)
let messages = ["hello, ", "world!\n"]
list.each(messages, fn(message) {
let assert Ok(_) = tcp.send(socket, message)
})
let assert Ok(_) = tcp.shutdown(socket)
let timeout_ms = 100
assert Ok("hello, world!\n") == tcp.receive(socket, timeout_ms)
// TODO find better way to always do cleanup
simplifile.delete(socket_path)
}