-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Check for rsync version * Use either `msgs2stderr` and `stderr=error` depending on the version * Unit tests for version-specific rsync commands * Adds github.com/mcuadros/go-version for comparing semantic versions
- Loading branch information
Showing
3 changed files
with
163 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
// +build aix darwin dragonfly freebsd js,wasm linux nacl netbsd openbsd solaris | ||
|
||
package datasetIngestor | ||
|
||
import ( | ||
"testing" | ||
"regexp" | ||
"strings" | ||
) | ||
|
||
func TestGetRsyncVersion(t *testing.T) { | ||
version, err := getRsyncVersion() | ||
if err != nil { | ||
t.Errorf("getRsyncVersion() returned an error: %v", err) | ||
} | ||
if version == "" { | ||
t.Error("getRsyncVersion() returned an empty string") | ||
} else { | ||
match, _ := regexp.MatchString(`^\d{1,2}\.\d{1,2}\.\d{1,2}$`, version) | ||
if !match { | ||
t.Error("getRsyncVersion() returned wrong version string format: ", version) | ||
} | ||
} | ||
} | ||
|
||
func TestBuildRsyncCmd(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
versionNumber string | ||
absFileListing string | ||
fullSourceFolder string | ||
serverConnectStr string | ||
expectedCmd string | ||
}{ | ||
{ | ||
name: "rsync version >= 3.2.3, absFileListing not empty", | ||
versionNumber: "3.2.3", | ||
absFileListing: "/path/to/file", | ||
fullSourceFolder: "/source/folder", | ||
serverConnectStr: "user@server:/dest/folder", | ||
expectedCmd: "/usr/bin/rsync -r --files-from /path/to/file -e ssh -avxz --progress --stderr=error /source/folder user@server:/dest/folder", | ||
}, | ||
{ | ||
name: "rsync version < 3.2.3, absFileListing not empty", | ||
versionNumber: "3.2.2", | ||
absFileListing: "/path/to/file", | ||
fullSourceFolder: "/source/folder", | ||
serverConnectStr: "user@server:/dest/folder", | ||
expectedCmd: "/usr/bin/rsync -r --files-from /path/to/file -e ssh -avxz --progress -q --msgs2stderr /source/folder user@server:/dest/folder", | ||
}, | ||
{ | ||
name: "rsync version >= 3.2.3, absFileListing empty", | ||
versionNumber: "3.2.3", | ||
absFileListing: "", | ||
fullSourceFolder: "/source/folder", | ||
serverConnectStr: "user@server:/dest/folder", | ||
expectedCmd: "/usr/bin/rsync -e ssh -avxz --progress --stderr=error /source/folder user@server:/dest/folder", | ||
}, | ||
{ | ||
name: "rsync version < 3.2.3, absFileListing empty", | ||
versionNumber: "3.2.2", | ||
absFileListing: "", | ||
fullSourceFolder: "/source/folder", | ||
serverConnectStr: "user@server:/dest/folder", | ||
expectedCmd: "/usr/bin/rsync -e ssh -avxz --progress -q --msgs2stderr /source/folder user@server:/dest/folder", | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
cmd := buildRsyncCmd(tt.versionNumber, tt.absFileListing, tt.fullSourceFolder, tt.serverConnectStr) | ||
cmdStr := strings.Join(cmd.Args, " ") | ||
if cmdStr != tt.expectedCmd { | ||
t.Errorf("Expected command: %s, got: %s", tt.expectedCmd, cmdStr) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters