go-hep.org/x/hep@v0.38.1/xrootd/xrdproto/endsess/endsess_test.go (about) 1 // Copyright ©2018 The go-hep Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package endsess_test 6 7 import ( 8 "reflect" 9 "testing" 10 11 "go-hep.org/x/hep/xrootd/internal/xrdenc" 12 "go-hep.org/x/hep/xrootd/xrdproto" 13 "go-hep.org/x/hep/xrootd/xrdproto/endsess" 14 ) 15 16 func TestRequest(t *testing.T) { 17 for _, want := range []endsess.Request{ 18 {}, 19 {SessionID: [16]byte{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}}, 20 } { 21 t.Run("", func(t *testing.T) { 22 var ( 23 err error 24 w = new(xrdenc.WBuffer) 25 got endsess.Request 26 ) 27 28 if want.ReqID() != endsess.RequestID { 29 t.Fatalf("invalid request ID: got=%d want=%d", want.ReqID(), endsess.RequestID) 30 } 31 32 if want.ShouldSign() { 33 t.Fatalf("invalid") 34 } 35 36 err = want.MarshalXrd(w) 37 if err != nil { 38 t.Fatalf("could not marshal request: %v", err) 39 } 40 41 r := xrdenc.NewRBuffer(w.Bytes()) 42 err = got.UnmarshalXrd(r) 43 if err != nil { 44 t.Fatalf("could not unmarshal request: %v", err) 45 } 46 47 if !reflect.DeepEqual(got, want) { 48 t.Fatalf("round trip failed:\ngot = %#v\nwant= %#v\n", got, want) 49 } 50 }) 51 } 52 } 53 54 var ( 55 _ xrdproto.Request = (*endsess.Request)(nil) 56 )