github.com/aergoio/aergo@v1.3.1/p2p/raftsupport/snapshotreceiver_test.go (about) 1 /* 2 * @file 3 * @copyright defined in aergo/LICENSE.txt 4 */ 5 6 package raftsupport 7 8 import ( 9 "bytes" 10 "testing" 11 12 "github.com/aergoio/aergo-lib/log" 13 "github.com/aergoio/aergo/types" 14 ) 15 16 func TestSnapshotReceiver_sendResp(t *testing.T) { 17 logger := log.NewLogger("raft.support.test") 18 type args struct { 19 resp *types.SnapshotResponse 20 } 21 tests := []struct { 22 name string 23 args args 24 }{ 25 {"TOK",args{&types.SnapshotResponse{Status:types.ResultStatus_OK,}}}, 26 {"TWrongHead",args{&types.SnapshotResponse{Status:types.ResultStatus_INVALID_ARGUMENT,Message:"wrong type"}}}, 27 {"TInternal",args{&types.SnapshotResponse{Status:types.ResultStatus_INTERNAL,Message:""}}}, 28 } 29 for _, tt := range tests { 30 t.Run(tt.name, func(t *testing.T) { 31 s := &snapshotReceiver{ 32 logger: logger, 33 } 34 w := &bytes.Buffer{} 35 s.sendResp(w, tt.args.resp) 36 37 if w.Len() < 4 { 38 t.Fatalf("snapshotReceiver.sendResp() = written %v bytes, want at least 4 bytes", w.Len()) 39 } 40 41 resp, err := readWireHSResp(w) 42 if err != nil { 43 t.Fatalf("readWireHSResp() err %v, want no error ", err.Error()) 44 } 45 if tt.args.resp.Status != resp.Status { 46 t.Fatalf("Response status %v, want %v",resp.Status.String(), tt.args.resp.Status.String() ) 47 } 48 if tt.args.resp.Message != resp.Message { 49 t.Fatalf("Response message %v, want %v",resp.Message, tt.args.resp.Message ) 50 } 51 }) 52 } 53 }