-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow env vars for all exec units from config (#152)
- Loading branch information
1 parent
587aa1c
commit 198ebfa
Showing
4 changed files
with
109 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
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,85 @@ | ||
package execunit | ||
|
||
import ( | ||
"strings" | ||
"testing" | ||
|
||
"github.com/klothoplatform/klotho/pkg/config" | ||
"github.com/klothoplatform/klotho/pkg/core" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func Test_environmentVarsAddedToUnit(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
envVars map[string]string | ||
want []core.EnvironmentVariable | ||
wantExecUnit bool | ||
}{ | ||
{ | ||
name: "no exec unit", | ||
envVars: map[string]string{ | ||
"key1": "value1", | ||
"key2": "value2", | ||
}, | ||
wantExecUnit: false, | ||
}, | ||
{ | ||
name: "add env vars", | ||
envVars: map[string]string{ | ||
"key1": "value1", | ||
"key2": "value2", | ||
}, | ||
want: []core.EnvironmentVariable{ | ||
{ | ||
Name: "key1", | ||
Value: "value1", | ||
}, | ||
{ | ||
Name: "key2", | ||
Value: "value2", | ||
}, | ||
}, | ||
wantExecUnit: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
assert := assert.New(t) | ||
|
||
cfg := config.Application{ | ||
ExecutionUnits: map[string]*config.ExecutionUnit{ | ||
"main": {EnvironmentVariables: tt.envVars}, | ||
}, | ||
} | ||
p := ExecUnitPlugin{Config: &cfg} | ||
result := &core.CompilationResult{} | ||
|
||
inputFiles := &core.InputFiles{} | ||
if tt.wantExecUnit { | ||
f, err := core.NewSourceFile("test", strings.NewReader("test"), testAnnotationLang) | ||
if assert.Nil(err) { | ||
inputFiles.Add(f) | ||
} | ||
} else { | ||
inputFiles.Add(&core.FileRef{ | ||
FPath: "test", | ||
}) | ||
} | ||
|
||
result.Add(inputFiles) | ||
err := p.Transform(result, &core.Dependencies{}) | ||
if !assert.NoError(err) { | ||
return | ||
} | ||
units := core.GetResourcesOfType[*core.ExecutionUnit](result) | ||
if tt.wantExecUnit { | ||
assert.Len(units, 1) | ||
assert.ElementsMatch(tt.want, units[0].EnvironmentVariables) | ||
} else { | ||
assert.Len(units, 0) | ||
} | ||
|
||
}) | ||
} | ||
} |
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