File: util_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 (37 lines) | stat: -rw-r--r-- 824 bytes parent folder | download
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
package tools

import (
	"bytes"
	"io"
	"os"
	"testing"

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

func TestCopyWithCallback(t *testing.T) {
	buf := bytes.NewBufferString("BOOYA")

	called := 0
	calledWritten := make([]int64, 0, 2)

	n, err := CopyWithCallback(io.Discard, buf, 5, func(total int64, written int64, current int) error {
		called += 1
		calledWritten = append(calledWritten, written)
		assert.Equal(t, 5, int(total))
		return nil
	})
	assert.Nil(t, err)
	assert.Equal(t, 5, int(n))

	assert.Equal(t, 1, called)
	assert.Len(t, calledWritten, 1)
	assert.Equal(t, 5, int(calledWritten[0]))
}

func TestMethodExists(t *testing.T) {
	// testing following methods exist in all platform.
	_, _ = CheckCloneFileSupported(os.TempDir())
	_, _ = CloneFile(io.Writer(nil), io.Reader(nil))
	_, _ = CloneFileByPath("", "")
}