aboutsummaryrefslogtreecommitdiff
path: root/hotline
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2022-06-28 21:51:43 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2022-06-28 21:51:43 -0700
commit7e6b49e4d6bf07cbd0df374460c92c1d88be0599 (patch)
tree641d8cc3debbf050c4ca7c8b3694e4fbd96e4ec3 /hotline
parentc681cfa3c4782b74c49a16bf08f2694cb9acba59 (diff)
Backfill file path test
Diffstat (limited to 'hotline')
-rw-r--r--hotline/file_path_test.go75
1 files changed, 75 insertions, 0 deletions
diff --git a/hotline/file_path_test.go b/hotline/file_path_test.go
index c2fa666..effd462 100644
--- a/hotline/file_path_test.go
+++ b/hotline/file_path_test.go
@@ -1,6 +1,7 @@
package hotline
import (
+ "fmt"
"github.com/stretchr/testify/assert"
"testing"
)
@@ -164,3 +165,77 @@ func Test_readPath(t *testing.T) {
})
}
}
+
+func Test_fileItemScanner(t *testing.T) {
+ type args struct {
+ data []byte
+ in1 bool
+ }
+ tests := []struct {
+ name string
+ args args
+ wantAdvance int
+ wantToken []byte
+ wantErr assert.ErrorAssertionFunc
+ }{
+ {
+ name: "when a full fileItem is provided",
+ args: args{
+ data: []byte{
+ 0, 0,
+ 0x09,
+ 0x73, 0x75, 0x62, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72,
+ },
+ in1: false,
+ },
+ wantAdvance: 12,
+ wantToken: []byte{
+ 0, 0,
+ 0x09,
+ 0x73, 0x75, 0x62, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72,
+ },
+ wantErr: assert.NoError,
+ },
+ {
+ name: "when a full fileItem with extra bytes is provided",
+ args: args{
+ data: []byte{
+ 0, 0,
+ 0x09,
+ 0x73, 0x75, 0x62, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72,
+ 1, 1, 1, 1, 1, 1,
+ },
+ in1: false,
+ },
+ wantAdvance: 12,
+ wantToken: []byte{
+ 0, 0,
+ 0x09,
+ 0x73, 0x75, 0x62, 0x66, 0x6f, 0x6c, 0x64, 0x65, 0x72,
+ },
+ wantErr: assert.NoError,
+ },
+ {
+ name: "when insufficient bytes are provided",
+ args: args{
+ data: []byte{
+ 0, 0,
+ },
+ in1: false,
+ },
+ wantAdvance: 0,
+ wantToken: []byte(nil),
+ wantErr: assert.NoError,
+ },
+ }
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ gotAdvance, gotToken, err := fileItemScanner(tt.args.data, tt.args.in1)
+ if !tt.wantErr(t, err, fmt.Sprintf("fileItemScanner(%v, %v)", tt.args.data, tt.args.in1)) {
+ return
+ }
+ assert.Equalf(t, tt.wantAdvance, gotAdvance, "fileItemScanner(%v, %v)", tt.args.data, tt.args.in1)
+ assert.Equalf(t, tt.wantToken, gotToken, "fileItemScanner(%v, %v)", tt.args.data, tt.args.in1)
+ })
+ }
+}