Skip to content

Commit

Permalink
👔 up: add more test case for env and parser
Browse files Browse the repository at this point in the history
  • Loading branch information
inhere committed Feb 6, 2023
1 parent ffabebb commit a7231ab
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
2 changes: 2 additions & 0 deletions dotenv/dotenv_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ func TestLoad(t *testing.T) {
assert.Err(t, err)

assert.Eq(t, "", os.Getenv("DONT_ENV_TEST"))
assert.Eq(t, "", os.Getenv("HTTP_URL_TEST"))

err = Load("./testdata")
assert.NoErr(t, err)
assert.Eq(t, "blog", os.Getenv("DONT_ENV_TEST"))
assert.Eq(t, "blog", Get("DONT_ENV_TEST"))
assert.Eq(t, "http://127.0.0.1:1081", Get("HTTP_URL_TEST"))
_ = os.Unsetenv("DONT_ENV_TEST") // clear

err = Load("./testdata", "error.ini")
Expand Down
1 change: 1 addition & 0 deletions dotenv/testdata/.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
# KEY=value

DONT_ENV_TEST="blog" # inline comments
HTTP_URL_TEST=http://127.0.0.1:1081 # comments2
21 changes: 21 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,24 @@ value at array
assert.Eq(t, "multi line\nvalue for key1\n", defMp["key1"])
assert.Eq(t, "multi line\nvalue at array\n", maputil.DeepGet(defMp, "arr.1"))
}

func TestParser_valueUrl(t *testing.T) {
p := NewLite()
err := p.ParseString(`
url_ip=http://127.0.0.1
url_ip_port=http://127.0.0.1:9090
url_value=https://github.com
url_value1=https://github.com/inhere
`)
assert.NoErr(t, err)
data := p.LiteData()
assert.NotEmpty(t, data)
defMap := data[DefSection]
assert.NotEmpty(t, defMap)
dump.P(defMap)

sMap := maputil.SMap(defMap)
assert.Eq(t, "http://127.0.0.1", sMap.Str("url_ip"))
assert.Eq(t, "http://127.0.0.1:9090", sMap.Str("url_ip_port"))
assert.Eq(t, "https://github.com/inhere", sMap.Str("url_value1"))
}

0 comments on commit a7231ab

Please sign in to comment.