aboutsummaryrefslogtreecommitdiff
path: root/awwan_env_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'awwan_env_test.go')
-rw-r--r--awwan_env_test.go73
1 files changed, 72 insertions, 1 deletions
diff --git a/awwan_env_test.go b/awwan_env_test.go
index 963658b..3fc6f67 100644
--- a/awwan_env_test.go
+++ b/awwan_env_test.go
@@ -11,6 +11,69 @@ import (
"github.com/shuLhan/share/lib/test"
)
+func TestAwwanEnvGet(t *testing.T) {
+ var (
+ baseDir = `testdata/env-get`
+
+ aww *Awwan
+ err error
+ )
+
+ aww, err = New(baseDir)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ type testCase struct {
+ desc string
+ dir string
+ key string
+ exp string
+ }
+ var cases = []testCase{{
+ desc: `withEmptyKey`,
+ dir: baseDir,
+ exp: `EnvGet: empty key`,
+ }, {
+ desc: `withMissingSection`,
+ dir: baseDir,
+ key: `::name`,
+ }, {
+ desc: `withMissingName`,
+ dir: baseDir,
+ key: `host`,
+ }, {
+ desc: `withValidName`,
+ dir: baseDir,
+ key: `host::name`,
+ exp: `localhost`,
+ }, {
+ desc: `fromVault`,
+ dir: baseDir,
+ key: `user:database:pass`,
+ exp: `s3cret`,
+ }, {
+ desc: `fromSubdirMyhost`,
+ dir: filepath.Join(baseDir, `myhost`),
+ key: `host::name`,
+ exp: `myhost`,
+ }}
+
+ var (
+ c testCase
+ got string
+ )
+ for _, c = range cases {
+ got, err = aww.EnvGet(c.dir, c.key)
+ if err != nil {
+ test.Assert(t, c.desc+` error`, c.exp, err.Error())
+ continue
+ }
+
+ test.Assert(t, c.desc, c.exp, got)
+ }
+}
+
func TestAwwanEnvSet(t *testing.T) {
var (
baseDir = t.TempDir()
@@ -19,7 +82,7 @@ func TestAwwanEnvSet(t *testing.T) {
err error
)
- testInitWorkspace(baseDir)
+ testInitWorkspace(baseDir, nil, nil)
tdata, err = test.LoadData(`testdata/env_set_test.data`)
if err != nil {
@@ -84,6 +147,7 @@ func TestAwwanEnvSet(t *testing.T) {
var (
c testCase
gotContent []byte
+ gotValue string
)
for _, c = range cases {
@@ -99,5 +163,12 @@ func TestAwwanEnvSet(t *testing.T) {
}
test.Assert(t, c.desc, c.exp, string(gotContent))
+
+ gotValue, err = aww.EnvGet(baseDir, c.key)
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ test.Assert(t, c.desc+` EnvGet`, c.val, gotValue)
}
}