-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
packer-sdc: return errors on duplicate tag/field
When generating the flattened structures for a HCL2-compatible config, we didn't prevent users from defining duplicate fields or tags, instead warning them. The warning in itself did not prevent the resulting structures from being generated, leading into a situation where the first definition of the arg/tag would have precedence over the subsequent definitions, leading to shadowing their definitions. To prevent this in the future, we immediately return an error when such a conflict is introduced, and signal to the user which attribute is problematic.
- Loading branch information
1 parent
e2f3241
commit d160ce0
Showing
4 changed files
with
98 additions
and
20 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
14 changes: 14 additions & 0 deletions
14
cmd/packer-sdc/internal/test-data/field-conflict/test_mapstructure_field_conflict.go
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,14 @@ | ||
package test | ||
|
||
type NestedOne struct { | ||
Arg int `mapstructure:"test"` | ||
} | ||
|
||
type NestedTwo struct { | ||
Arg int `mapstructure:"test"` | ||
} | ||
|
||
type Config struct { | ||
NestedOne `mapstructure:",squash"` | ||
NestedTwo `mapstructure:",squash"` | ||
} |
14 changes: 14 additions & 0 deletions
14
cmd/packer-sdc/internal/test-data/tag-conflict/test_mapstructure_tag_conflict.go
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,14 @@ | ||
package test | ||
|
||
type NestedOne struct { | ||
Arg int `mapstructure:"test"` | ||
} | ||
|
||
type NestedTwo struct { | ||
Args int `mapstructure:"test"` | ||
} | ||
|
||
type Config struct { | ||
NestedOne `mapstructure:",squash"` | ||
NestedTwo `mapstructure:",squash"` | ||
} |