-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixing interpreting empty list as null value (#3317)
* fix: convert empty value to null value * chore: update test * chore: update test * chore: unit test improvements * chore: code improvements
- Loading branch information
1 parent
acbc58a
commit 8e8192a
Showing
4 changed files
with
76 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,59 @@ | ||
package config | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
"github.com/stretchr/testify/require" | ||
"github.com/zclconf/go-cty/cty" | ||
) | ||
|
||
func TestUpdateUnknownCtyValValues(t *testing.T) { | ||
t.Parallel() | ||
|
||
testCases := []struct { | ||
value cty.Value | ||
expectedValue cty.Value | ||
}{ | ||
{ | ||
cty.ListVal([]cty.Value{cty.ObjectVal(map[string]cty.Value{ | ||
"items": cty.ListVal([]cty.Value{cty.ObjectVal(map[string]cty.Value{ | ||
"firstname": cty.StringVal("joo"), | ||
"lastname": cty.UnknownVal(cty.String), | ||
})}), | ||
})}), | ||
cty.ListVal([]cty.Value{cty.ObjectVal(map[string]cty.Value{ | ||
"items": cty.ListVal([]cty.Value{cty.ObjectVal(map[string]cty.Value{ | ||
"firstname": cty.StringVal("joo"), | ||
"lastname": cty.StringVal(""), | ||
})}), | ||
})}), | ||
}, | ||
{ | ||
cty.ListVal([]cty.Value{cty.ObjectVal(map[string]cty.Value{})}), | ||
cty.ListVal([]cty.Value{cty.ObjectVal(map[string]cty.Value{})}), | ||
}, | ||
{ | ||
cty.ObjectVal(map[string]cty.Value{}), | ||
cty.ObjectVal(map[string]cty.Value{}), | ||
}, | ||
{ | ||
cty.ObjectVal(map[string]cty.Value{"key": cty.UnknownVal(cty.String)}), | ||
cty.ObjectVal(map[string]cty.Value{"key": cty.StringVal("")}), | ||
}, | ||
} | ||
|
||
for i, testCase := range testCases { | ||
testCase := testCase | ||
|
||
t.Run(fmt.Sprintf("testCase-%d", i), func(t *testing.T) { | ||
t.Parallel() | ||
|
||
actualValue, err := updateUnknownCtyValValues(testCase.value) | ||
require.NoError(t, err) | ||
|
||
assert.Equal(t, testCase.expectedValue, actualValue) | ||
}) | ||
} | ||
} |
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