| 1 | package lfs |
| 2 | |
| 3 | import ( |
| 4 | "bufio" |
| 5 | "strings" |
| 6 | "testing" |
| 7 | |
| 8 | "github.com/stretchr/testify/assert" |
| 9 | ) |
| 10 | |
| 11 | func TestCatFileBatchCheckScannerWithValidOutput(t *testing.T) { |
| 12 | lines := []string{ |
| 13 | "short line", |
| 14 | "0000000000000000000000000000000000000000 BLOB capitalized", |
| 15 | "0000000000000000000000000000000000000001 blob not-a-size", |
| 16 | "0000000000000000000000000000000000000002 blob 123", |
| 17 | "0000000000000000000000000000000000000003 blob 1 0", |
| 18 | "0000000000000000000000000000000000000004 blob 123456789", |
| 19 | } |
| 20 | r := strings.NewReader(strings.Join(lines, "\n")) |
| 21 | s := &catFileBatchCheckScanner{ |
| 22 | s: bufio.NewScanner(r), |
| 23 | limit: 1024, |
| 24 | } |
| 25 | |
| 26 | assertNextOID(t, s, "", "") |
| 27 | assertNextOID(t, s, "", "") |
| 28 | assertNextOID(t, s, "", "") |
| 29 | assertNextOID(t, s, "0000000000000000000000000000000000000002", "") |
| 30 | assertNextOID(t, s, "", "") |
| 31 | assertNextOID(t, s, "", "0000000000000000000000000000000000000004") |
| 32 | assertScannerDone(t, s) |
| 33 | assert.Equal(t, "", s.LFSBlobOID()) |
| 34 | assert.Equal(t, "", s.GitBlobOID()) |
| 35 | } |
| 36 | |
| 37 | type stringScanner interface { |
| 38 | Next() (string, bool, error) |
| 39 | Err() error |
| 40 | Scan() bool |
| 41 | } |
| 42 | |
| 43 | type genericScanner interface { |
| 44 | Err() error |
| 45 | Scan() bool |
| 46 | } |
| 47 | |
| 48 | func assertNextScan(t *testing.T, scanner genericScanner) { |
| 49 | assert.True(t, scanner.Scan()) |
| 50 | assert.Nil(t, scanner.Err()) |
| 51 | } |
| 52 | |
| 53 | func assertNextOID(t *testing.T, scanner *catFileBatchCheckScanner, lfsBlobOID, gitBlobOID string) { |
| 54 | assertNextScan(t, scanner) |
| 55 | assert.Equal(t, lfsBlobOID, scanner.LFSBlobOID()) |
| 56 | assert.Equal(t, gitBlobOID, scanner.GitBlobOID()) |
| 57 | } |
| 58 | |
| 59 | func assertScannerDone(t *testing.T, scanner genericScanner) { |
| 60 | assert.False(t, scanner.Scan()) |
| 61 | assert.Nil(t, scanner.Err()) |
| 62 | } |