-
-
Notifications
You must be signed in to change notification settings - Fork 193
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding new functions
bool
and getenv
Two new functions: - `getenv` - a more forgiving way to get an environment variable - `bool` - converts a string into a boolean Also enabled multi-line templates by reading the entire input before applying the template, instead of applying the template one line at a time. Signed-off-by: Dave Henderson <dhenderson@gmail.com>
- Loading branch information
1 parent
e96a78e
commit fc17cc1
Showing
3 changed files
with
144 additions
and
13 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
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,40 @@ | ||
package main | ||
|
||
import ( | ||
"bytes" | ||
"os" | ||
"strings" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func testTemplate(template string) string { | ||
in := strings.NewReader(template) | ||
var out bytes.Buffer | ||
RunTemplate(in, &out) | ||
return strings.TrimSpace(out.String()) | ||
} | ||
|
||
func TestGetenv(t *testing.T) { | ||
assert.Empty(t, Getenv("FOOBARBAZ")) | ||
assert.Empty(t, testTemplate(`{{getenv "BLAHBLAHBLAH"}}`)) | ||
assert.Equal(t, Getenv("USER"), os.Getenv("USER")) | ||
assert.Equal(t, os.Getenv("USER"), testTemplate(`{{getenv "USER"}}`)) | ||
} | ||
|
||
func TestBool(t *testing.T) { | ||
assert.False(t, Bool("")) | ||
assert.False(t, Bool("asdf")) | ||
assert.False(t, Bool("1234")) | ||
assert.False(t, Bool("False")) | ||
assert.False(t, Bool("0")) | ||
assert.False(t, Bool("false")) | ||
assert.False(t, Bool("F")) | ||
assert.False(t, Bool("f")) | ||
assert.True(t, Bool("true")) | ||
assert.True(t, Bool("True")) | ||
assert.True(t, Bool("t")) | ||
assert.True(t, Bool("T")) | ||
assert.True(t, Bool("1")) | ||
} |