aboutsummaryrefslogtreecommitdiff
path: root/hotline/transfer_test.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2021-08-06 16:46:45 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2021-08-06 16:46:45 -0700
commitdf2735b25a21d839746be31b43edb9e348086b0a (patch)
tree7aaa5672d8aede4830bae006ac743b0de413b2f4 /hotline/transfer_test.go
parent8dea0e8234db79daeb40544b4b3426d8ce76f3e5 (diff)
Minor cleanup of transfer
Diffstat (limited to 'hotline/transfer_test.go')
-rw-r--r--hotline/transfer_test.go95
1 files changed, 93 insertions, 2 deletions
diff --git a/hotline/transfer_test.go b/hotline/transfer_test.go
index 52044b0..63e22c0 100644
--- a/hotline/transfer_test.go
+++ b/hotline/transfer_test.go
@@ -2,6 +2,97 @@ package hotline
import "testing"
-func TestReadTransfer(t *testing.T) {
-
+func TestTransfer_Read(t *testing.T) {
+ type fields struct {
+ Protocol [4]byte
+ ReferenceNumber [4]byte
+ DataSize [4]byte
+ RSVD [4]byte
+ }
+ type args struct {
+ b []byte
+ }
+ tests := []struct {
+ name string
+ fields fields
+ args args
+ want int
+ wantErr bool
+ }{
+ {
+ name: "when b is a valid transfer",
+ fields: fields{
+ Protocol: [4]byte{},
+ ReferenceNumber: [4]byte{},
+ DataSize: [4]byte{},
+ RSVD: [4]byte{},
+ },
+ args: args{
+ b: []byte{
+ 0x48, 0x54, 0x58, 0x46,
+ 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x02,
+ 0x00, 0x00, 0x00, 0x00,
+ },
+ },
+ want: 16,
+ wantErr: false,
+ },
+ {
+ name: "when b contains invalid transfer protocol",
+ fields: fields{
+ Protocol: [4]byte{},
+ ReferenceNumber: [4]byte{},
+ DataSize: [4]byte{},
+ RSVD: [4]byte{},
+ },
+ args: args{
+ b: []byte{
+ 0x11, 0x11, 0x11, 0x11,
+ 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x02,
+ 0x00, 0x00, 0x00, 0x00,
+ },
+ },
+ want: 0,
+ wantErr: true,
+ },
+ {
+ name: "when b does not contain expected len of bytes",
+ fields: fields{
+ Protocol: [4]byte{},
+ ReferenceNumber: [4]byte{},
+ DataSize: [4]byte{},
+ RSVD: [4]byte{},
+ },
+ args: args{
+ b: []byte{
+ 0x48, 0x54, 0x58, 0x46,
+ 0x00, 0x00, 0x00, 0x01,
+ 0x00, 0x00, 0x00, 0x02,
+ 0x00, 0x00, 0x00,
+ },
+ },
+ want: 0,
+ wantErr: true,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ tf := &transfer{
+ Protocol: tt.fields.Protocol,
+ ReferenceNumber: tt.fields.ReferenceNumber,
+ DataSize: tt.fields.DataSize,
+ RSVD: tt.fields.RSVD,
+ }
+ got, err := tf.Write(tt.args.b)
+ if (err != nil) != tt.wantErr {
+ t.Errorf("Read() error = %v, wantErr %v", err, tt.wantErr)
+ return
+ }
+ if got != tt.want {
+ t.Errorf("Read() got = %v, want %v", got, tt.want)
+ }
+ })
+ }
}