diff options
| author | Shulhan <ms@kilabit.info> | 2023-11-17 03:18:52 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2023-11-17 03:18:52 +0700 |
| commit | 19f5053c19bdd2f9f4f764eb17ef0f096eb87f3e (patch) | |
| tree | 2c6553269f2c3d562fb9f0f7950268c90dd6a198 /awwan_test.go | |
| parent | 68cbc52f2195063a0b4c9ce8c6c4cf030182c53a (diff) | |
| download | awwan-19f5053c19bdd2f9f4f764eb17ef0f096eb87f3e.tar.xz | |
all: implement command "env-get" to get value from environment files
The env-get command get the value from environment files.
Syntax,
----
<key> [dir]
----
The "key" argument define the key where value is stored in environment
using "section:sub:name" format.
The "dir" argument is optional, its define the directory where environment
files will be loaded, recursively, from BaseDir to dir.
If its empty default to the current directory.
Diffstat (limited to 'awwan_test.go')
| -rw-r--r-- | awwan_test.go | 31 |
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) + } } } |
