Skip to content

Commit

Permalink
test(local): SyncLocalFile
Browse files Browse the repository at this point in the history
longhorn/longhorn-4105

Signed-off-by: Chin-Ya Huang <[email protected]>
  • Loading branch information
c3y1huang committed Jul 1, 2024
1 parent 257f15e commit ebe4de4
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
4 changes: 2 additions & 2 deletions sparse/rest/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func (it *IdleTimer) ConnState(conn net.Conn, state http.ConnState) {
}
}

func (t *IdleTimer) Done() <-chan time.Time {
return t.timer.C
func (it *IdleTimer) Done() <-chan time.Time {
return it.timer.C
}

type DataSyncServer interface {
Expand Down
42 changes: 42 additions & 0 deletions sparse/test/local_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package test

import (
"bytes"
"os"

"testing"

. "github.com/longhorn/sparse-tools/sparse"
)

func TestSyncLocalFile(t *testing.T) {
layoutFrom := []FileInterval{
{Kind: SparseData, Interval: Interval{Begin: 0, End: 1 * Blocks}},
{Kind: SparseHole, Interval: Interval{Begin: 1 * Blocks, End: 2 * Blocks}},
{Kind: SparseData, Interval: Interval{Begin: 2 * Blocks, End: 3 * Blocks}},
}

sourceFilePath := tempFilePath("sync-local-src-")
targetFilePath := tempFilePath("sync-local-dst-")

createTestSparseFile(sourceFilePath, layoutFrom)

err := SyncLocalFile(sourceFilePath, targetFilePath)
if err != nil {
t.Fatal("Failed to sync local file", err)
}

sourceData, err := os.ReadFile(sourceFilePath)
if err != nil {
t.Fatal("Failed to read source file", err)
}

targetData, err := os.ReadFile(targetFilePath)
if err != nil {
t.Fatal("Failed to read target file", err)
}

if !bytes.Equal(sourceData, targetData) {
t.Fatal("Source and target files are different")
}
}

0 comments on commit ebe4de4

Please sign in to comment.