-
Notifications
You must be signed in to change notification settings - Fork 0
/
awwan_test.go
62 lines (52 loc) · 1.24 KB
/
awwan_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
// SPDX-FileCopyrightText: 2023 M. Shulhan <[email protected]>
// SPDX-License-Identifier: GPL-3.0-or-later
package awwan
import (
"log"
"os"
"path/filepath"
"testing"
"time"
)
func TestMain(m *testing.M) {
defLogTimeFormat = `----/--/-- --:--:--`
timeNow = func() time.Time {
return time.Date(2023, time.November, 26, 15, 21, 00, 00, time.UTC)
}
os.Exit(m.Run())
}
// testInitWorkspace initialize the awwan workspace with ".ssh" directory
// and optional "awwan.key" and "awwan.pass" file.
func testInitWorkspace(dir string, awwanKey, awwanPass []byte) {
var (
logp = `testInitWorkspace`
dirSSH = filepath.Join(dir, defSSHDir)
)
var err = os.Mkdir(dirSSH, 0700)
if err != nil {
log.Fatalf(`%s: %s`, logp, err)
}
var file string
if len(awwanKey) != 0 {
file = filepath.Join(dirSSH, defFilePrivateKey)
err = os.WriteFile(file, awwanKey, 0600)
if err != nil {
log.Fatalf(`%s: %s`, logp, err)
}
}
if len(awwanPass) != 0 {
file = filepath.Join(dirSSH, defFilePassphrase)
err = os.WriteFile(file, awwanPass, 0600)
if err != nil {
log.Fatalf(`%s: %s`, logp, err)
}
}
}
func mockOsGetwd(t *testing.T, dir string) {
t.Cleanup(func() {
osGetwd = os.Getwd
})
osGetwd = func() (string, error) {
return dir, nil
}
}