39 lines
1.2 KiB
Gleam
39 lines
1.2 KiB
Gleam
import gleam/erlang/process
|
|
import gleam/otp/task
|
|
import gleeunit/should
|
|
import mug
|
|
import treevault
|
|
|
|
pub fn main() {
|
|
server_test()
|
|
}
|
|
|
|
pub fn server_test() {
|
|
let _ = task.async(treevault.main)
|
|
process.sleep(2000)
|
|
|
|
let assert Ok(socket) =
|
|
mug.new("localhost", port: 8080)
|
|
|> mug.timeout(milliseconds: 500)
|
|
|> mug.connect()
|
|
|
|
let assert Ok(Nil) = mug.send(socket, <<"set root.a 2":utf8>>)
|
|
let assert Ok(packet) = mug.receive(socket, timeout_milliseconds: 100)
|
|
packet |> should.equal(<<"Ok":utf8>>)
|
|
|
|
let assert Ok(Nil) = mug.send(socket, <<"get root.a":utf8>>)
|
|
let assert Ok(packet) = mug.receive(socket, timeout_milliseconds: 100)
|
|
packet |> should.equal(<<"2":utf8>>)
|
|
|
|
let assert Ok(Nil) = mug.send(socket, <<"foo root.a":utf8>>)
|
|
let assert Ok(packet) = mug.receive(socket, timeout_milliseconds: 100)
|
|
packet |> should.equal(<<"QueryError(\"Wrong query format.\")":utf8>>)
|
|
|
|
let assert Ok(Nil) = mug.send(socket, <<"set root.b \"foo\"":utf8>>)
|
|
let assert Ok(_) = mug.receive(socket, timeout_milliseconds: 100)
|
|
let assert Ok(Nil) = mug.send(socket, <<"rget root":utf8>>)
|
|
let assert Ok(packet) = mug.receive(socket, timeout_milliseconds: 100)
|
|
|
|
packet |> should.equal(<<"{\"a\":2,\"b\":\"foo\"}":utf8>>)
|
|
}
|