-
-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Values without a backing env var should not be expanded (#368)
* Values without a backing env var should not be expanded * Add unit tests for sourcing behavior * Replace godotenv with shell lib
- Loading branch information
Showing
10 changed files
with
123 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: Run Unit Tests | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-22.04 | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Setup Go | ||
uses: actions/setup-go@v4 | ||
with: | ||
go-version: '1.22.x' | ||
- name: Install dependencies | ||
run: go mod download | ||
- name: Test with the Go CLI | ||
run: go test -v ./... |
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,68 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestSource(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
input string | ||
expectError bool | ||
expectedOutput map[string]string | ||
}{ | ||
{ | ||
"default", | ||
"testdata/default.env", | ||
false, | ||
map[string]string{ | ||
"FOO": "bar", | ||
"BAZ": "qux", | ||
}, | ||
}, | ||
{ | ||
"not found", | ||
"testdata/nope.env", | ||
true, | ||
nil, | ||
}, | ||
{ | ||
"braces", | ||
"testdata/braces.env", | ||
false, | ||
map[string]string{ | ||
"FOO": "qux", | ||
"BAR": "xxx", | ||
"BAZ": "", | ||
}, | ||
}, | ||
{ | ||
"expansion", | ||
"testdata/expansion.env", | ||
false, | ||
map[string]string{ | ||
"BAR": "xxx", | ||
"FOO": "xxx", | ||
"BAZ": "xxx", | ||
"QUX": "yyy", | ||
}, | ||
}, | ||
} | ||
|
||
os.Setenv("QUX", "yyy") | ||
defer os.Unsetenv("QUX") | ||
|
||
for _, test := range tests { | ||
t.Run(test.name, func(t *testing.T) { | ||
result, err := source(test.input) | ||
if (err != nil) != test.expectError { | ||
t.Errorf("Unexpected error value %v", err) | ||
} | ||
if !reflect.DeepEqual(test.expectedOutput, result) { | ||
t.Errorf("Expected %v, got %v", test.expectedOutput, 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
FOO=${bar:-qux} | ||
BAR=xxx | ||
BAZ=$NOPE |
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,2 @@ | ||
FOO=bar | ||
BAZ=qux |
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,4 @@ | ||
BAR=xxx | ||
FOO=${BAR} | ||
BAZ=$BAR | ||
QUX=${QUX} |
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 |
---|---|---|
@@ -1,2 +1,3 @@ | ||
NAME="other" | ||
BACKUP_CRON_EXPRESSION="*/1 * * * *" | ||
BACKUP_FILENAME="override-$NAME.tar.gz" |
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