This repository has been archived by the owner on Sep 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
220fd42
commit 3881a99
Showing
3 changed files
with
55 additions
and
7 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,46 @@ | ||
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
// or more contributor license agreements. Licensed under the Elastic License; | ||
// you may not use this file except in compliance with the Elastic License. | ||
|
||
package shell | ||
|
||
import ( | ||
"os" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestGetEnvBool(t *testing.T) { | ||
type test struct { | ||
key string | ||
value string | ||
} | ||
|
||
tests := []test{ | ||
{key: "should_be_true", value: "true"}, | ||
{key: "should_be_false", value: "false"}, | ||
{key: "should_be_empty", value: ""}, | ||
{key: "should_be_not_empty", value: "garbage"}, | ||
} | ||
|
||
for _, test := range tests { | ||
os.Setenv(test.key, test.value) | ||
|
||
val, err := GetEnvBool(test.key) | ||
|
||
if test.key == "should_be_empty" { | ||
assert.NotNil(t, err) | ||
assert.False(t, val) | ||
} else if test.key == "should_be_not_empty" { | ||
assert.Nil(t, err) | ||
assert.False(t, val) | ||
} else if test.key == "should_be_true" { | ||
assert.Nil(t, err) | ||
assert.True(t, val) | ||
} else if test.key == "should_be_false" { | ||
assert.Nil(t, err) | ||
assert.False(t, val) | ||
} | ||
} | ||
} |
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