-
Notifications
You must be signed in to change notification settings - Fork 2
/
testclient.lua
60 lines (42 loc) · 1.2 KB
/
testclient.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
-- SPDX-License-Identifier: MIT
-- Copyright (c) 2014-2020 Iruatã Martins dos Santos Souza
local data = require'data'
local np = require'9p'
local conn = np.newconn(io.read,
function (buf)
io.write(buf)
io.output():flush()
end)
conn:attach("iru", "")
local f, g = conn:newfid(), conn:newfid()
conn:walk(conn.rootfid, f, "/tmp")
conn:clone(f, g)
conn:create(g, "file", 420, 1)
local ftext = "this is a test\n"
local buf = data.new(ftext)
local n = conn:write(g, 0, buf)
if n ~= #buf then
error("test: expected to write " .. #buf .. " bytes but wrote " .. n)
end
conn:clunk(g)
if pcall(np.walk, conn, conn.rootfid, g,
"/tmp/.lua9p.non.existant..") ~= false then
error("test: succeeded when shouldn't (walking to non-existing file)")
end
conn:walk(conn.rootfid, g, "/tmp/file")
conn:open(g, 0)
local st = conn:stat(g)
-- Remove last byte of the file
st.length = st.length - 1
conn:wstat(g, st)
buf = conn:read(g, 0, st.length)
conn:remove(g)
buf:layout{str = {0, #buf, 'string'}}
-- The trailing \n was removed by wstat, we add it again to check the read
if buf.str .. "\n" == ftext then
io.stderr:write("test ok\n")
else
error("test failed")
end
conn:clunk(f)
conn:clunk(conn.rootfid)