-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #385 from segmentio/mckern/fix-env-vars
Fix `chamber env` and `chamber export -f dotenv`
- Loading branch information
Showing
6 changed files
with
242 additions
and
67 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,54 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
func Test_validateShellName(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
str string | ||
shouldFail bool | ||
}{ | ||
{name: "strings with spaces should fail", str: "invalid strings", shouldFail: true}, | ||
{name: "strings with only underscores should pass", str: "valid_string", shouldFail: false}, | ||
{name: "strings with dashes should fail", str: "validish-string", shouldFail: true}, | ||
{name: "strings that start with numbers should fail", str: "1invalidstring", shouldFail: true}, | ||
{name: "strings that start with underscores should pass", str: "_1validstring", shouldFail: false}, | ||
{name: "strings that contain periods should fail", str: "invalid.string", shouldFail: true}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
if err := validateShellName(tt.str); (err != nil) != tt.shouldFail { | ||
t.Errorf("validateShellName error: %v, expect wantErr %v", err, tt.shouldFail) | ||
} | ||
}) | ||
} | ||
} | ||
|
||
func Test_sanitizeKey(t *testing.T) { | ||
tests := []struct { | ||
given string | ||
expected string | ||
}{ | ||
{given: "invalid strings", expected: "invalid_strings"}, | ||
{given: "extremely invalid strings", expected: "extremely__invalid__strings"}, | ||
{given: fmt.Sprintf("\nunbelievably\tinvalid\tstrings\n"), expected: "unbelievably_invalid_strings"}, | ||
{given: "valid_string", expected: "valid_string"}, | ||
{given: "validish-string", expected: "validish_string"}, | ||
{given: "valid.string", expected: "valid_string"}, | ||
// the following two strings should not be corrected, simply returned as-is. | ||
{given: "1invalidstring", expected: "1invalidstring"}, | ||
{given: "_1validstring", expected: "_1validstring"}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run("test sanitizing key names", func(t *testing.T) { | ||
if got := sanitizeKey(tt.given); got != tt.expected { | ||
t.Errorf("shellName error: want %q, got %q", tt.expected, got) | ||
} | ||
}) | ||
} | ||
} |
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
Oops, something went wrong.