feat: agent keeps SSH file sessions and runs file operations on the host by commands
This commit is contained in:
1 parent
f5d6bd30e8
commit
2859e69abe
4 files changed
+607
No files matched your search
@@ -0,0 +1,47 @@
|
||||
package agent
|
||||
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseStatLine(t *testing.T) {
|
||||
// statCommand prints: type|size|mtime|mode|name
|
||||
e, ok := parseStatLine("directory|4096|1760000000|drwxr-xr-x|my dir")
|
||||
if !ok || !e.IsDir || e.Name != "my dir" || e.MTime != 1760000000 || e.Mode != "drwxr-xr-x" {
|
||||
t.Fatalf("dir: %+v %v", e, ok)
|
||||
}
|
||||
e, ok = parseStatLine("regular file|12|1760000001|-rw-r--r--|a|b.txt")
|
||||
if !ok || e.IsDir || e.Size != 12 || e.Name != "a|b.txt" {
|
||||
t.Fatalf("file with | in name: %+v %v", e, ok)
|
||||
}
|
||||
if _, ok := parseStatLine("garbage"); ok {
|
||||
t.Fatal("garbage parsed")
|
||||
}
|
||||
}
|
||||
|
||||
func TestStatCommandQuotes(t *testing.T) {
|
||||
for _, fl := range []string{"gnu", "bsd"} {
|
||||
c := statCommand(fl, "/srv/it's here")
|
||||
if !strings.Contains(c, `'/srv/it'\''s here/'`) {
|
||||
t.Errorf("%s: dir not quoted: %s", fl, c)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseLsLine(t *testing.T) {
|
||||
e, ok := parseLsLine("-rw-r--r-- 1 root root 1234 Oct 15 10:00 my file.txt")
|
||||
if !ok || e.Name != "my file.txt" || e.Size != 1234 || e.IsDir {
|
||||
t.Fatalf("file: %+v %v", e, ok)
|
||||
}
|
||||
e, ok = parseLsLine("lrwxrwxrwx 1 root root 7 Oct 15 10:00 link -> target")
|
||||
if !ok || e.Name != "link" {
|
||||
t.Fatalf("link: %+v %v", e, ok)
|
||||
}
|
||||
if _, ok := parseLsLine("drwxr-xr-x 2 root root 4096 Oct 15 10:00 .."); ok {
|
||||
t.Fatal(".. listed")
|
||||
}
|
||||
if _, ok := parseLsLine("total 8"); ok {
|
||||
t.Fatal("total parsed")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user