commit f6980e26d2d95b490f1f4018b6ef086e496212d9
parent 7f859b6f3974be1a81eb24098f1d6dfc00658690
Author: Matsuda Kenji <info@mtkn.jp>
Date: Sat, 13 Jan 2024 14:42:35 +0900
modify test
Diffstat:
2 files changed, 31 insertions(+), 34 deletions(-)
diff --git a/server.go b/server.go
@@ -150,7 +150,6 @@ func (c *conn) runResponder(ctx context.Context, rp *reqPool) {
return
}
r.ofcall.SetTag(r.tag)
- // free tag.
rp.delete(r.tag)
_, err := c.w.Write(r.ofcall.marshal())
if err != nil {
diff --git a/server_test.go b/server_test.go
@@ -139,37 +139,35 @@ func TestGetReq(t *testing.T) {
func TestSVersion(t *testing.T) {
tests := []struct {
- input *request
- want *request
+ input *TVersion
+ want Msg
}{
- {&request{ifcall: &TVersion{Msize: 1024, Version: "9P2000"}},
- &request{ofcall: &RVersion{Msize: 1024, Version: "9P2000"}}},
- {&request{ifcall: &TVersion{Msize: 564, Version: "9P2000"}},
- &request{ofcall: &RVersion{Msize: 564, Version: "9P2000"}}},
- {&request{ifcall: &TVersion{Msize: 8 * 1024, Version: "9P2000"}},
- &request{ofcall: &RVersion{Msize: 1024, Version: "9P2000"}}},
- {&request{ifcall: &TVersion{Msize: 1024, Version: "unko"}},
- &request{ofcall: &RVersion{Msize: 1024, Version: "unknown"}}},
+ {&TVersion{Msize: 1024, Version: "9P2000"},
+ &RVersion{Msize: 1024, Version: "9P2000"}},
+ {&TVersion{Msize: 564, Version: "9P2000"},
+ &RVersion{Msize: 564, Version: "9P2000"}},
+ {&TVersion{Msize: 8 * 1024, Version: "9P2000"},
+ &RVersion{Msize: 1024, Version: "9P2000"}},
+ {&TVersion{Msize: 1024, Version: "unko"},
+ &RVersion{Msize: 1024, Version: "unknown"}},
}
c, rc := setupConn(nil)
tc := make(chan *request)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go sVersion(ctx, c, tc)
- for _, test := range tests {
+ for i, test := range tests {
oldMsize := c.msize
- tc <- test.input
- ifcall := test.input.ifcall.(*TVersion)
- wantmsg := test.want.ofcall.(*RVersion)
- gotmsg := (<-rc).ofcall.(*RVersion)
- if !reflect.DeepEqual(wantmsg, gotmsg) {
- t.Errorf("want: %v,\n\tgot: %v", wantmsg, gotmsg)
+ tc <- &request{ifcall: test.input}
+ got := (<-rc).ofcall.(*RVersion)
+ if !reflect.DeepEqual(test.want, got) {
+ t.Errorf("%d: want: %v,\n\tgot: %v", i, test.want, got)
}
- if ifcall.Msize < oldMsize && c.msize != ifcall.Msize {
- t.Errorf("msize not changed")
+ if test.input.Msize < oldMsize && c.msize != test.input.Msize {
+ t.Errorf("%d: msize not changed", i)
}
- if ifcall.Msize >= oldMsize && c.msize != oldMsize {
- t.Errorf("msize changed unexpectedly")
+ if test.input.Msize >= oldMsize && c.msize != oldMsize {
+ t.Errorf("%d: msize changed unexpectedly", i)
}
c.msize = oldMsize
}
@@ -177,22 +175,22 @@ func TestSVersion(t *testing.T) {
func TestSAuth(t *testing.T) {
tests := []struct {
- input *request
- want *request
+ input *TAuth
+ want Msg
authFunc func(context.Context, *request)
}{
- {&request{ifcall: &TAuth{Afid: NOFID, Uname: "kenji", Aname: ""}},
- &request{ofcall: &RError{Ename: errors.New("authentication not required")}}, nil},
- {&request{ifcall: &TAuth{Afid: NOFID, Uname: "kenji", Aname: ""}},
- &request{ofcall: &RError{Ename: errors.New("NOFID can't be used for afid")}},
+ {&TAuth{Afid: NOFID, Uname: "kenji", Aname: ""},
+ &RError{Ename: errors.New("authentication not required")}, nil},
+ {&TAuth{Afid: NOFID, Uname: "kenji", Aname: ""},
+ &RError{Ename: errors.New("NOFID can't be used for afid")},
func(ctx context.Context, r *request) {}},
- {&request{ifcall: &TAuth{Afid: 0, Uname: "kenji", Aname: ""}},
- &request{ofcall: &RAuth{Tag: 0, Aqid: Qid{0, 1, 2}}},
+ {&TAuth{Afid: 0, Uname: "kenji", Aname: ""},
+ &RAuth{Tag: 0, Aqid: Qid{0, 1, 2}},
func(ctx context.Context, r *request) {
r.ofcall = &RAuth{Tag: 0, Aqid: Qid{0, 1, 2}}
}},
- {&request{ifcall: &TAuth{Afid: 0, Uname: "kenji", Aname: "fs"}},
- &request{ofcall: &RError{Ename: errors.New("no such file system")}},
+ {&TAuth{Afid: 0, Uname: "kenji", Aname: "fs"},
+ &RError{Ename: errors.New("no such file system")},
func(ctx context.Context, r *request) {
r.ofcall = &RAuth{Tag: 0, Aqid: Qid{0, 1, 2}}
}},
@@ -205,9 +203,9 @@ func TestSAuth(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go sAuth(ctx, c, tc)
- tc <- test.input
+ tc <- &request{ifcall: test.input}
ofcall := (<-rc).ofcall
- switch wantmsg := test.want.ofcall.(type) {
+ switch wantmsg := test.want.(type) {
case *RAuth:
gotmsg, ok := ofcall.(*RAuth)
if !ok {