Skip to content

Commit ebe4de4

Browse files
committed
test(local): SyncLocalFile
longhorn/longhorn-4105 Signed-off-by: Chin-Ya Huang <[email protected]>
1 parent 257f15e commit ebe4de4

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

sparse/rest/server.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ func (it *IdleTimer) ConnState(conn net.Conn, state http.ConnState) {
5050
}
5151
}
5252

53-
func (t *IdleTimer) Done() <-chan time.Time {
54-
return t.timer.C
53+
func (it *IdleTimer) Done() <-chan time.Time {
54+
return it.timer.C
5555
}
5656

5757
type DataSyncServer interface {

sparse/test/local_test.go

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package test
2+
3+
import (
4+
"bytes"
5+
"os"
6+
7+
"testing"
8+
9+
. "github.com/longhorn/sparse-tools/sparse"
10+
)
11+
12+
func TestSyncLocalFile(t *testing.T) {
13+
layoutFrom := []FileInterval{
14+
{Kind: SparseData, Interval: Interval{Begin: 0, End: 1 * Blocks}},
15+
{Kind: SparseHole, Interval: Interval{Begin: 1 * Blocks, End: 2 * Blocks}},
16+
{Kind: SparseData, Interval: Interval{Begin: 2 * Blocks, End: 3 * Blocks}},
17+
}
18+
19+
sourceFilePath := tempFilePath("sync-local-src-")
20+
targetFilePath := tempFilePath("sync-local-dst-")
21+
22+
createTestSparseFile(sourceFilePath, layoutFrom)
23+
24+
err := SyncLocalFile(sourceFilePath, targetFilePath)
25+
if err != nil {
26+
t.Fatal("Failed to sync local file", err)
27+
}
28+
29+
sourceData, err := os.ReadFile(sourceFilePath)
30+
if err != nil {
31+
t.Fatal("Failed to read source file", err)
32+
}
33+
34+
targetData, err := os.ReadFile(targetFilePath)
35+
if err != nil {
36+
t.Fatal("Failed to read target file", err)
37+
}
38+
39+
if !bytes.Equal(sourceData, targetData) {
40+
t.Fatal("Source and target files are different")
41+
}
42+
}

0 commit comments

Comments
 (0)