diff --git a/go.mod b/go.mod index 1d85ed2..dbd8c5a 100644 --- a/go.mod +++ b/go.mod @@ -83,6 +83,7 @@ require ( filippo.io/edwards25519 v1.1.0 // indirect git.sr.ht/~rockorager/vaxis v0.10.3 // indirect github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96 // indirect + github.com/DavidGamba/go-getoptions v0.29.0 // indirect github.com/Masterminds/goutils v1.1.1 // indirect github.com/Masterminds/semver/v3 v3.2.0 // indirect github.com/Masterminds/sprig/v3 v3.2.3 // indirect @@ -198,6 +199,7 @@ require ( github.com/google/cel-go v0.20.1 // indirect github.com/google/flatbuffers v23.1.21+incompatible // indirect github.com/google/pprof v0.0.0-20240711041743-f6c9dda6c6da // indirect + github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect github.com/gorilla/css v1.0.1 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-immutable-radix v1.3.1 // indirect diff --git a/go.sum b/go.sum index 29703c1..eadbfe8 100644 --- a/go.sum +++ b/go.sum @@ -23,6 +23,8 @@ github.com/AndreasBriese/bbloom v0.0.0-20190825152654-46b345b51c96/go.mod h1:bOv github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3tL4fMGNddJ+vMq1mwgfaqoQ= +github.com/DavidGamba/go-getoptions v0.29.0 h1:cU8MjOyfAyPZke4hrgEuiGBJHS9PFYPAHve2fhDhdDk= +github.com/DavidGamba/go-getoptions v0.29.0/go.mod h1:zE97E3PR9P3BI/HKyNYgdMlYxodcuiC6W68KIgeYT84= github.com/Masterminds/goutils v1.1.1 h1:5nUrii3FMTL5diU80unEVvNevw1nH4+ZV4DSLVJLSYI= github.com/Masterminds/goutils v1.1.1/go.mod h1:8cTjp+g8YejhMuvIA5y2vz3BpJxksy863GQaJW2MFNU= github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs= @@ -441,6 +443,8 @@ github.com/google/pprof v0.0.0-20240711041743-f6c9dda6c6da/go.mod h1:K1liHPHnj73 github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/s2a-go v0.1.8 h1:zZDs9gcbt9ZPLV0ndSyQk6Kacx2g/X+SKYovpnz3SMM= github.com/google/s2a-go v0.1.8/go.mod h1:6iNWHTpQ+nfNRN5E00MSdfDwVesa8hhS32PhPO8deJA= +github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaUGG7oYTSPP8MxqL4YI3kZKwcP4= +github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ= github.com/google/uuid v1.1.1/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= diff --git a/pgs/ssh_test.go b/pgs/ssh_test.go index 62bdeb4..5591e41 100644 --- a/pgs/ssh_test.go +++ b/pgs/ssh_test.go @@ -132,6 +132,7 @@ func TestSshServerRsync(t *testing.T) { if err != nil { panic(err) } + defer os.RemoveAll(name) // remove the temporary directory at the end of the program // defer os.RemoveAll(name) @@ -184,10 +185,9 @@ func TestSshServerRsync(t *testing.T) { // copy files cmd := exec.Command("rsync", "-rv", "-e", eCmd, name+"/", "localhost:/test") - fmt.Println(cmd.Args) result, err := cmd.CombinedOutput() if err != nil { - fmt.Println(string(result), err) + cfg.Logger.Error("cannot upload", "err", err, "result", string(result)) t.Error(err) return } @@ -205,6 +205,55 @@ func TestSshServerRsync(t *testing.T) { return } + dlName, err := os.MkdirTemp("", "rsync-download") + if err != nil { + panic(err) + } + defer os.RemoveAll(dlName) + + // download files + downloadCmd := exec.Command("rsync", "-rv", "-e", eCmd, "localhost:/test/", dlName+"/") + result, err = downloadCmd.CombinedOutput() + if err != nil { + cfg.Logger.Error("cannot download files", "err", err, "result", string(result)) + t.Error(err) + return + } + + // check contents + idx, err := os.ReadFile(filepath.Join(dlName, "index.html")) + if err != nil { + cfg.Logger.Error("cannot open file", "file", "index.html", "err", err) + t.Error(err) + return + } + if string(idx) != index { + t.Error("downloaded index.html file does not match original") + return + } + + abt, err := os.ReadFile(filepath.Join(dlName, "about.html")) + if err != nil { + cfg.Logger.Error("cannot open file", "file", "about.html", "err", err) + t.Error(err) + return + } + if string(abt) != about { + t.Error("downloaded about.html file does not match original") + return + } + + cnt, err := os.ReadFile(filepath.Join(dlName, "contact.html")) + if err != nil { + cfg.Logger.Error("cannot open file", "file", "contact.html", "err", err) + t.Error(err) + return + } + if string(cnt) != contact { + t.Error("downloaded contact.html file does not match original") + return + } + // remove about file os.Remove(aboutFile) @@ -212,7 +261,7 @@ func TestSshServerRsync(t *testing.T) { delCmd := exec.Command("rsync", "-rv", "--delete", "-e", eCmd, name+"/", "localhost:/test") result, err = delCmd.CombinedOutput() if err != nil { - fmt.Println(string(result), err) + cfg.Logger.Error("cannot upload with delete", "err", err, "result", string(result)) t.Error(err) return }