-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil_test.go
More file actions
74 lines (63 loc) · 1.21 KB
/
util_test.go
File metadata and controls
74 lines (63 loc) · 1.21 KB
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
package bichme
import (
"bufio"
"context"
"io"
"log/slog"
"os"
"path/filepath"
"testing"
"github.com/pkg/sftp"
)
var ctx = context.Background()
var devNull *os.File
func init() {
var err error
devNull, err = os.Open(os.DevNull)
if err != nil {
panic(err)
}
}
func discardStdout(t *testing.T) {
init := os.Stdout
t.Cleanup(func() { os.Stdout = init })
os.Stdout = devNull
}
func discardLogs(t *testing.T) {
t.Helper()
orig := slog.Default()
t.Cleanup(func() { slog.SetDefault(orig) })
slog.SetDefault(slog.New(slog.DiscardHandler))
}
func makeHistoryEntry(t *testing.T, root, date, tm string) string {
t.Helper()
path := filepath.Join(root, date, tm)
if err := os.MkdirAll(path, 0755); err != nil {
t.Fatal(err)
}
return path
}
func readLines(r io.Reader) []string {
var lines []string
scanner := bufio.NewScanner(r)
for scanner.Scan() {
lines = append(lines, scanner.Text())
}
return lines
}
func dialAndSFTP(t *testing.T, j *Job) {
t.Helper()
if err := j.Dial(ctx); err != nil {
t.Fatal(err)
}
var err error
j.sftp, err = sftp.NewClient(j.ssh)
if err != nil {
t.Fatal(err)
}
}
func cancelledCtx() context.Context {
ctx, cancel := context.WithCancel(ctx)
cancel()
return ctx
}