aboutsummaryrefslogtreecommitdiff
path: root/awwan_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'awwan_test.go')
-rw-r--r--awwan_test.go31
1 files changed, 27 insertions, 4 deletions
diff --git a/awwan_test.go b/awwan_test.go
index 3198737..ab656cc 100644
--- a/awwan_test.go
+++ b/awwan_test.go
@@ -4,6 +4,7 @@
package awwan
import (
+ "log"
"os"
"path/filepath"
"testing"
@@ -15,11 +16,33 @@ func TestMain(m *testing.M) {
os.Exit(m.Run())
}
-func testInitWorkspace(dir string) {
- var path = filepath.Join(dir, defSshDir)
+// 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(path, 0700)
+ var err = os.Mkdir(dirSsh, 0700)
if err != nil {
- panic(err)
+ 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)
+ }
}
}