repos / pico

pico services mono repo
git clone https://github.com/picosh/pico.git

commit
c3bfb7e
parent
9bd9552
author
Antonio Mika
date
2025-02-25 14:52:17 -0500 EST
Work on sender tests
1 files changed,  +43, -3
M pgs/ssh_test.go
+43, -3
 1@@ -184,10 +184,9 @@ func TestSshServerRsync(t *testing.T) {
 2 
 3 	// copy files
 4 	cmd := exec.Command("rsync", "-rv", "-e", eCmd, name+"/", "localhost:/test")
 5-	fmt.Println(cmd.Args)
 6 	result, err := cmd.CombinedOutput()
 7 	if err != nil {
 8-		fmt.Println(string(result), err)
 9+		cfg.Logger.Error("cannot upload", "err", err, "result", string(result))
10 		t.Error(err)
11 		return
12 	}
13@@ -212,7 +211,7 @@ func TestSshServerRsync(t *testing.T) {
14 	delCmd := exec.Command("rsync", "-rv", "--delete", "-e", eCmd, name+"/", "localhost:/test")
15 	result, err = delCmd.CombinedOutput()
16 	if err != nil {
17-		fmt.Println(string(result), err)
18+		cfg.Logger.Error("cannot upload with delete", "err", err, "result", string(result))
19 		t.Error(err)
20 		return
21 	}
22@@ -225,6 +224,47 @@ func TestSshServerRsync(t *testing.T) {
23 		return
24 	}
25 
26+	dlName, err := os.MkdirTemp("", "rsync-download")
27+	if err != nil {
28+		panic(err)
29+	}
30+	defer os.RemoveAll(dlName)
31+	// download files
32+	downloadCmd := exec.Command("rsync", "-rvvv", "-e", eCmd, "localhost:/test/", dlName+"/")
33+	result, err = downloadCmd.CombinedOutput()
34+	if err != nil {
35+		cfg.Logger.Error("cannot download files", "err", err, "result", string(result))
36+		t.Error(err)
37+		return
38+	}
39+	// check contents
40+	idx, err := os.ReadFile(filepath.Join(dlName, "index.html"))
41+	if err != nil {
42+		cfg.Logger.Error("cannot open file", "file", "index.html", "err", err)
43+		t.Error(err)
44+		return
45+	}
46+	if string(idx) != index {
47+		t.Error("downloaded index.html file does not match original")
48+		return
49+	}
50+	_, err = os.ReadFile(filepath.Join(dlName, "about.html"))
51+	if err == nil {
52+		cfg.Logger.Error("about file should not exist", "file", "about.html")
53+		t.Error(err)
54+		return
55+	}
56+	cnt, err := os.ReadFile(filepath.Join(dlName, "contact.html"))
57+	if err != nil {
58+		cfg.Logger.Error("cannot open file", "file", "contact.html", "err", err)
59+		t.Error(err)
60+		return
61+	}
62+	if string(cnt) != contact {
63+		t.Error("downloaded contact.html file does not match original")
64+		return
65+	}
66+
67 	close(done)
68 
69 	p, err := os.FindProcess(os.Getpid())