Skip to content

Commit

Permalink
test: add test for multiple tag options
Browse files Browse the repository at this point in the history
Signed-off-by: Carlos Alexandro Becker <[email protected]>
  • Loading branch information
caarlos0 committed Jun 19, 2024
1 parent 57aa5b2 commit ba8b0d2
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2127,3 +2127,27 @@ func TestIssue310(t *testing.T) {
isNoErr(t, err)
isEqual(t, nil, cfg.URL)
}

func TestMultipleTagOptions(t *testing.T) {
type TestConfig struct {
URL *url.URL `env:"URL,init,unset"`
}
t.Run("unset", func(t *testing.T) {
cfg, err := ParseAs[TestConfig]()
isNoErr(t, err)
isEqual(t, &url.URL{}, cfg.URL)
})
t.Run("empty", func(t *testing.T) {
t.Setenv("URL", "")
cfg, err := ParseAs[TestConfig]()
isNoErr(t, err)
isEqual(t, &url.URL{}, cfg.URL)
})
t.Run("set", func(t *testing.T) {
t.Setenv("URL", "https://github.com/caarlos0")
cfg, err := ParseAs[TestConfig]()
isNoErr(t, err)
isEqual(t, &url.URL{Scheme: "https", Host: "github.com", Path: "/caarlos0"}, cfg.URL)
isEqual(t, "", os.Getenv("URL"))
})
}

0 comments on commit ba8b0d2

Please sign in to comment.