-
Notifications
You must be signed in to change notification settings - Fork 165
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Juan Bustamante <jbustamante@vmware.com>
- Loading branch information
1 parent
d6a81be
commit 9b07b40
Showing
3 changed files
with
132 additions
and
11 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,121 @@ | ||
package cnb | ||
|
||
import ( | ||
"github.com/stretchr/testify/assert" | ||
"testing" | ||
|
||
"github.com/sclevine/spec" | ||
) | ||
|
||
func TestEnvVariable(t *testing.T) { | ||
spec.Run(t, "EnvVariable", testEnvVariable) | ||
} | ||
|
||
func testEnvVariable(t *testing.T, when spec.G, it spec.S) { | ||
|
||
var ( | ||
variableA, variableB envVariable | ||
envVariables, otherEnvVariables []envVariable | ||
) | ||
|
||
when("#containsEnvVar", func() { | ||
when("slide is undefined", func() { | ||
it.Before(func() { | ||
envVariables = nil | ||
variableA = envVariable{} | ||
}) | ||
|
||
it("returns false", func() { | ||
assert.False(t, containsEnvVar(envVariables, variableA)) | ||
}) | ||
}) | ||
|
||
when("slide is defined", func() { | ||
it.Before(func() { | ||
variableA = envVariable{Name: "NameA", Value: "ValueA"} | ||
envVariables = []envVariable{variableA} | ||
}) | ||
|
||
when("element is present in the slide", func() { | ||
it("returns true", func() { | ||
assert.True(t, containsEnvVar(envVariables, envVariable{Name: "NameA", Value: "Whatever"})) | ||
}) | ||
}) | ||
|
||
when("element is not present in the slide", func() { | ||
it("returns false", func() { | ||
assert.False(t, containsEnvVar(envVariables, envVariable{Name: "NameB", Value: "Whatever"})) | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
when("#mergeEnvVariables", func() { | ||
when("slides are undefined", func() { | ||
when("both slides are undefined", func() { | ||
it.Before(func() { | ||
envVariables = nil | ||
otherEnvVariables = nil | ||
}) | ||
|
||
it("returns nil", func() { | ||
merged := mergeEnvVariables(envVariables, otherEnvVariables) | ||
assert.Nil(t, merged) | ||
}) | ||
}) | ||
|
||
when("one of the slide is undefined", func() { | ||
it.Before(func() { | ||
envVariables = nil | ||
variableA = envVariable{Name: "NameA", Value: "ValueA"} | ||
otherEnvVariables = []envVariable{variableA} | ||
}) | ||
|
||
when("old slide is undefined", func() { | ||
it("returns new slide", func() { | ||
merged := mergeEnvVariables(envVariables, otherEnvVariables) | ||
assert.Equal(t, otherEnvVariables, merged) | ||
}) | ||
}) | ||
|
||
when("new slide is undefined", func() { | ||
it("returns old slide", func() { | ||
merged := mergeEnvVariables(otherEnvVariables, envVariables) | ||
assert.Equal(t, otherEnvVariables, merged) | ||
}) | ||
}) | ||
}) | ||
|
||
when("slides are defined", func() { | ||
when("element in old slide does not exist in new slide", func() { | ||
it.Before(func() { | ||
variableA = envVariable{Name: "NameA", Value: "ValueA"} | ||
variableB = envVariable{Name: "NameB", Value: "ValueB"} | ||
envVariables = []envVariable{variableA} | ||
otherEnvVariables = []envVariable{variableB} | ||
}) | ||
|
||
it("element is added to the merge slide", func() { | ||
merged := mergeEnvVariables(envVariables, otherEnvVariables) | ||
expected := []envVariable{variableB, variableA} | ||
assert.Equal(t, expected, merged) | ||
}) | ||
}) | ||
|
||
when("element in old slide is also defined in new slide", func() { | ||
it.Before(func() { | ||
variableA = envVariable{Name: "NameA", Value: "ValueA"} | ||
variableB = envVariable{Name: "NameA", Value: "OtherValue"} | ||
envVariables = []envVariable{variableA} | ||
otherEnvVariables = []envVariable{variableB} | ||
}) | ||
|
||
it("element in new slide has precedence", func() { | ||
merged := mergeEnvVariables(envVariables, otherEnvVariables) | ||
assert.Equal(t, otherEnvVariables, merged) | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) | ||
} |
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