-
Notifications
You must be signed in to change notification settings - Fork 441
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
e708470
commit fdecb4a
Showing
5 changed files
with
50 additions
and
3 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
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,15 @@ | ||
package sprig | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
) | ||
|
||
func mustEnv(env string) (string, error){ | ||
v, ok := os.LookupEnv(env) | ||
if !ok { | ||
return v, fmt.Errorf("env var \"%s\" does not exist", env) | ||
} | ||
|
||
return v, nil | ||
} |
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,20 @@ | ||
package sprig | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestMustEnv(t *testing.T) { | ||
tpl := `{{ mustEnv "INVALID" }}` | ||
if err := runt(tpl, "foo"); err == nil { | ||
t.Errorf("expected error, got: %v", err) | ||
} | ||
|
||
t.Setenv("TMP", "OK") | ||
|
||
tpl = `{{ mustEnv "TMP" }}` | ||
if err := runt(tpl, "OK"); err != nil { | ||
t.Error(err) | ||
} | ||
|
||
} |