File: gitscanner_catfilebatchcheckscanner_test.go

package info (click to toggle)
git-lfs 3.6.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,808 kB
  • sloc: sh: 21,256; makefile: 507; ruby: 417
file content (62 lines) | stat: -rw-r--r-- 1,622 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package lfs

import (
	"bufio"
	"strings"
	"testing"

	"github.com/stretchr/testify/assert"
)

func TestCatFileBatchCheckScannerWithValidOutput(t *testing.T) {
	lines := []string{
		"short line",
		"0000000000000000000000000000000000000000 BLOB capitalized",
		"0000000000000000000000000000000000000001 blob not-a-size",
		"0000000000000000000000000000000000000002 blob 123",
		"0000000000000000000000000000000000000003 blob 1 0",
		"0000000000000000000000000000000000000004 blob 123456789",
	}
	r := strings.NewReader(strings.Join(lines, "\n"))
	s := &catFileBatchCheckScanner{
		s:     bufio.NewScanner(r),
		limit: 1024,
	}

	assertNextOID(t, s, "", "")
	assertNextOID(t, s, "", "")
	assertNextOID(t, s, "", "")
	assertNextOID(t, s, "0000000000000000000000000000000000000002", "")
	assertNextOID(t, s, "", "")
	assertNextOID(t, s, "", "0000000000000000000000000000000000000004")
	assertScannerDone(t, s)
	assert.Equal(t, "", s.LFSBlobOID())
	assert.Equal(t, "", s.GitBlobOID())
}

type stringScanner interface {
	Next() (string, bool, error)
	Err() error
	Scan() bool
}

type genericScanner interface {
	Err() error
	Scan() bool
}

func assertNextScan(t *testing.T, scanner genericScanner) {
	assert.True(t, scanner.Scan())
	assert.Nil(t, scanner.Err())
}

func assertNextOID(t *testing.T, scanner *catFileBatchCheckScanner, lfsBlobOID, gitBlobOID string) {
	assertNextScan(t, scanner)
	assert.Equal(t, lfsBlobOID, scanner.LFSBlobOID())
	assert.Equal(t, gitBlobOID, scanner.GitBlobOID())
}

func assertScannerDone(t *testing.T, scanner genericScanner) {
	assert.False(t, scanner.Scan())
	assert.Nil(t, scanner.Err())
}