go-hep.org/x/hep@v0.38.1/xrootd/xrdproto/decrypt/decrypt_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 decrypt_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/decrypt"
    14  )
    15  
    16  func TestRequest(t *testing.T) {
    17  	for _, want := range []decrypt.Request{
    18  		{},
    19  	} {
    20  		t.Run("", func(t *testing.T) {
    21  			var (
    22  				err error
    23  				w   = new(xrdenc.WBuffer)
    24  				got decrypt.Request
    25  			)
    26  
    27  			if want.ReqID() != decrypt.RequestID {
    28  				t.Fatalf("invalid request ID: got=%d want=%d", want.ReqID(), decrypt.RequestID)
    29  			}
    30  
    31  			if want.ShouldSign() {
    32  				t.Fatalf("invalid")
    33  			}
    34  
    35  			err = want.MarshalXrd(w)
    36  			if err != nil {
    37  				t.Fatalf("could not marshal request: %v", err)
    38  			}
    39  
    40  			r := xrdenc.NewRBuffer(w.Bytes())
    41  			err = got.UnmarshalXrd(r)
    42  			if err != nil {
    43  				t.Fatalf("could not unmarshal request: %v", err)
    44  			}
    45  
    46  			if !reflect.DeepEqual(got, want) {
    47  				t.Fatalf("round trip failed:\ngot = %#v\nwant= %#v\n", got, want)
    48  			}
    49  		})
    50  	}
    51  }
    52  
    53  var (
    54  	_ xrdproto.Request = (*decrypt.Request)(nil)
    55  )