forked from go-acme/lego
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Route53: Make it possible to configure from the env (go-acme#603)
- Loading branch information
Showing
5 changed files
with
134 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package env | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func Test_GetOrDefaultInt(t *testing.T) { | ||
testCases := []struct { | ||
desc string | ||
envValue string | ||
defaultValue int | ||
expected int | ||
}{ | ||
{ | ||
desc: "valid value", | ||
envValue: "100", | ||
defaultValue: 2, | ||
expected: 100, | ||
}, | ||
{ | ||
desc: "invalid content, use default value", | ||
envValue: "abc123", | ||
defaultValue: 2, | ||
expected: 2, | ||
}, | ||
{ | ||
desc: "valid negative value", | ||
envValue: "-111", | ||
defaultValue: 2, | ||
expected: -111, | ||
}, | ||
{ | ||
desc: "float: invalid type, use default value", | ||
envValue: "1.11", | ||
defaultValue: 2, | ||
expected: 2, | ||
}, | ||
} | ||
|
||
const key = "LEGO_ENV_TC" | ||
|
||
for _, test := range testCases { | ||
t.Run(test.desc, func(t *testing.T) { | ||
defer os.Unsetenv(key) | ||
err := os.Setenv(key, test.envValue) | ||
require.NoError(t, err) | ||
|
||
result := GetOrDefaultInt(key, test.defaultValue) | ||
assert.Equal(t, test.expected, result) | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters