aboutsummaryrefslogtreecommitdiff
path: root/awwan_env_test.go
diff options
context:
space:
mode:
authorShulhan <ms@kilabit.info>2024-01-16 22:00:38 +0700
committerShulhan <ms@kilabit.info>2024-01-16 22:22:19 +0700
commit71b40922e6b6cc4f2d4b3fa94cbe586720bf6f8c (patch)
treee66171fb37dd51af1ac1b09beb02339b4f66ed92 /awwan_env_test.go
parenta1339c8b1fb34d272426f97ca42cecd7971e627c (diff)
downloadawwan-71b40922e6b6cc4f2d4b3fa94cbe586720bf6f8c.tar.xz
all: refactoring "env-set" arguments
Previously, the "env-set" take the file argument as the last argument and optional. This changes move the file argument to the first argument so the bash completion can detect and print the completion for list of keys. While at it, fix handling key with quoted in EnvSet and EnvGet. Closes: https://todo.sr.ht/~shulhan/awwan/10
Diffstat (limited to 'awwan_env_test.go')
-rw-r--r--awwan_env_test.go24
1 files changed, 13 insertions, 11 deletions
diff --git a/awwan_env_test.go b/awwan_env_test.go
index ce386c9..fdefec0 100644
--- a/awwan_env_test.go
+++ b/awwan_env_test.go
@@ -164,6 +164,11 @@ func TestAwwanEnvSet(t *testing.T) {
var file = filepath.Join(baseDir, `awwan.env`)
var cases = []testCase{{
+ desc: `withEmptyFile`,
+ key: `host::ip_internal`,
+ val: `127.0.0.1`,
+ exp: string(tdata.Output[`withEmptyFile:error`]),
+ }, {
desc: `withEmptyKey`,
file: file,
exp: string(tdata.Output[`withEmptyKey:error`]),
@@ -191,16 +196,17 @@ func TestAwwanEnvSet(t *testing.T) {
val: `awwan`,
exp: string(tdata.Output[`withFileNotExist`]),
}, {
- desc: `withEmptyFile`,
- key: `host::ip_internal`,
- val: `127.0.0.1`,
- exp: string(tdata.Output[`withEmptyFile`]),
- }, {
desc: `withOverwriteValue`,
file: file,
key: `host::name`,
val: `overwrite`,
exp: string(tdata.Output[`withOverwriteValue`]),
+ }, {
+ desc: `withQuotedString`,
+ file: file,
+ key: `"host:my:name"`,
+ val: `my-host`,
+ exp: string(tdata.Output[`withQuotedString`]),
}}
var (
@@ -210,17 +216,13 @@ func TestAwwanEnvSet(t *testing.T) {
)
for _, c = range cases {
- err = aww.EnvSet(c.key, c.val, c.file)
+ err = aww.EnvSet(c.file, c.key, c.val)
if err != nil {
test.Assert(t, c.desc, c.exp, err.Error())
continue
}
- if len(c.file) == 0 {
- gotContent, err = os.ReadFile(file)
- } else {
- gotContent, err = os.ReadFile(c.file)
- }
+ gotContent, err = os.ReadFile(c.file)
if err != nil {
t.Fatal(err)
}