lib9p

Go 9P library.
Log | Files | Refs | LICENSE

commit 6f8cf9d673e4b93ef41d83deaef0bcd5b884edb9
parent ef65aa51d1331f9390bd2dfa1af26c6d32cec5d2
Author: Matsuda Kenji <info@mtkn.jp>
Date:   Wed,  3 Jan 2024 08:02:01 +0900

sClunk to return RError when fid is unknown

Diffstat:
Mserver.go | 3+--
Mserver_test.go | 18+++++++++++++++---
2 files changed, 16 insertions(+), 5 deletions(-)

diff --git a/server.go b/server.go @@ -900,8 +900,7 @@ func sClunk(ctx context.Context, c *conn, rc <-chan *request) { r.ofcall = &RClunk{} resp: if r.err != nil { - log.Printf("clunk: %v", r.err) - r.ofcall = &RClunk{} + setError(r, r.err) } select { case c.respChan <- r: diff --git a/server_test.go b/server_test.go @@ -622,10 +622,11 @@ func TestSClunk(t *testing.T) { tests := []struct{ fid uint32 ifcall *TClunk + want Msg }{ - {0, &TClunk{Fid: 0}}, - {0, &TClunk{Fid: 1}}, - {1, &TClunk{Fid: 1}}, + {0, &TClunk{Fid: 0}, &RClunk{}}, + {0, &TClunk{Fid: 1}, &RError{}}, + {1, &TClunk{Fid: 1}, &RClunk{}}, } c, tc, rc := setupConn(testfs) ctx, cancel := context.WithCancel(context.Background()) @@ -643,6 +644,11 @@ func TestSClunk(t *testing.T) { ofcall := (<-rc).ofcall switch ofcall := ofcall.(type) { case *RClunk: + if _, ok := test.want.(*RClunk); !ok { + t.Errorf("%d: unexpected message:\n\twant: %v\n\tgot: %v", + i, test.want, ofcall) + return + } if _, ok := c.fPool.lookup(test.fid); ok { if test.fid == test.ifcall.Fid { t.Errorf("%d: fid not flushed", i) @@ -652,6 +658,12 @@ func TestSClunk(t *testing.T) { t.Errorf("%d: wrong fid flushed", i) } } + case *RError: + if _, ok := test.want.(*RError); !ok { + t.Errorf("%d: unexpected message:\n\twant: %v\n\tgot: %v", + i, test.want, ofcall) + return + } default: t.Errorf("%d: unexpected message %v", i, ofcall) }