-
Notifications
You must be signed in to change notification settings - Fork 1
/
iago_test.go
82 lines (71 loc) · 1.46 KB
/
iago_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
package iago_test
import (
"context"
"os"
"path/filepath"
"strings"
"testing"
. "github.com/relab/iago"
"github.com/relab/iago/iagotest"
)
func TestIago(t *testing.T) {
dir := t.TempDir()
wd, err := os.Getwd()
if err != nil {
t.Fatal(err)
}
g := iagotest.CreateSSHGroup(t, 4, false)
g.ErrorHandler = func(e error) {
t.Fatal(e)
}
g.Run(
"Custom Shell Command",
func(ctx context.Context, host Host) (err error) {
var sb strings.Builder
err = Shell{
Command: "lsb_release -a",
Stdout: &sb,
}.Apply(ctx, host)
if err != nil {
return err
}
t.Log(sb.String())
return nil
})
g.Run("Read distribution name", Shell{Command: "grep '^ID=' /etc/os-release > $HOME/os"}.Apply)
g.Run("Upload a file", func(ctx context.Context, host Host) error {
src, err := NewPath(wd, "LICENSE")
if err != nil {
return err
}
dest, err := NewPath(Expand(host, "$HOME"), "LICENSE")
if err != nil {
return err
}
return Upload{
Src: src,
Dest: dest,
}.Apply(ctx, host)
})
g.Run("Download files", func(ctx context.Context, host Host) error {
src, err := NewPath(Expand(host, "$HOME"), "os")
if err != nil {
return err
}
dest, err := NewPath(dir, "os")
if err != nil {
return err
}
return Download{
Src: src,
Dest: dest,
}.Apply(ctx, host)
})
for i := range g.Hosts {
f, err := os.ReadFile(filepath.Join(dir, "os."+g.Hosts[i].Name()))
if err != nil {
t.Fatal(err)
}
t.Log(string(f))
}
}