Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions cli/compose/template/template_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,20 +175,24 @@ func TestSubstituteWithCustomFunc(t *testing.T) {

func TestExtractVariables(t *testing.T) {
testCases := []struct {
name string
dict map[string]interface{}
expected map[string]string
}{
{
name: "empty",
dict: map[string]interface{}{},
expected: map[string]string{},
},
{
name: "no-variables",
dict: map[string]interface{}{
"foo": "bar",
},
expected: map[string]string{},
},
{
name: "variable-without-curly-braces",
dict: map[string]interface{}{
"foo": "$bar",
},
Expand All @@ -197,6 +201,7 @@ func TestExtractVariables(t *testing.T) {
},
},
{
name: "variable",
dict: map[string]interface{}{
"foo": "${bar}",
},
Expand All @@ -205,6 +210,7 @@ func TestExtractVariables(t *testing.T) {
},
},
{
name: "required-variable",
dict: map[string]interface{}{
"foo": "${bar?:foo}",
},
Expand All @@ -213,6 +219,7 @@ func TestExtractVariables(t *testing.T) {
},
},
{
name: "required-variable2",
dict: map[string]interface{}{
"foo": "${bar?foo}",
},
Expand All @@ -221,6 +228,7 @@ func TestExtractVariables(t *testing.T) {
},
},
{
name: "default-variable",
dict: map[string]interface{}{
"foo": "${bar:-foo}",
},
Expand All @@ -229,6 +237,7 @@ func TestExtractVariables(t *testing.T) {
},
},
{
name: "default-variable2",
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I'm sure you can find a better name 😛

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll let you that pleasure 😛

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can't, I'm only a humble reviewer 😇

dict: map[string]interface{}{
"foo": "${bar-foo}",
},
Expand All @@ -237,6 +246,7 @@ func TestExtractVariables(t *testing.T) {
},
},
{
name: "multiple-values",
dict: map[string]interface{}{
"foo": "${bar:-foo}",
"bar": map[string]interface{}{
Expand All @@ -259,7 +269,9 @@ func TestExtractVariables(t *testing.T) {
},
}
for _, tc := range testCases {
actual := ExtractVariables(tc.dict, defaultPattern)
assert.Check(t, is.DeepEqual(actual, tc.expected))
t.Run(tc.name, func(t *testing.T) {
actual := ExtractVariables(tc.dict, defaultPattern)
assert.Check(t, is.DeepEqual(actual, tc.expected))
})
}
}