Move echo_server to tests
This commit is contained in:
@@ -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
30
test/tcp/tcp_test.gleam
Normal 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)
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user