Skip to content

Commit

Permalink
chore: make test-case and comment for removing dots from extracted id…
Browse files Browse the repository at this point in the history
… params more verbose

This should make it clearer in the future what this case is for, and if it breaks
  • Loading branch information
UnseenWizzard committed Aug 23, 2024
1 parent ceb38ec commit 46fff06
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pkg/download/id_extraction/id_extraction.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ func findAllIds(content string) []string {

func createParameterKey(id string) string {
idKey := strings.ReplaceAll(id, "-", "_") // golang template keys must not contain hyphens
idKey = strings.ReplaceAll(idKey, ".", "_") // replace any dots with "_" as well, to avoid nested parameter definitions
idKey = strings.ReplaceAll(idKey, ".", "_") // monaco templating would treat any dot as referencing a nested sub-key in value parameters, but we're just building simple key:val parameters
return fmt.Sprintf("id_%s", idKey)
}
32 changes: 29 additions & 3 deletions pkg/download/id_extraction/id_extraction_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ func TestScopeParameterIsTreatedAsParameter(t *testing.T) {
{
Template: template.NewInMemoryTemplate("test-tmpl", "{}"),
Parameters: config.Parameters{
"scope": value.New("HOST-123456789.9"),
"scope": value.New("HOST-123456789"),
},
},
},
Expand All @@ -319,9 +319,35 @@ func TestScopeParameterIsTreatedAsParameter(t *testing.T) {
{
Template: template.NewInMemoryTemplate("test-tmpl", "{}"),
Parameters: config.Parameters{
"scope": &ref.ReferenceParameter{ParameterReference: parameter.ParameterReference{Property: baseParamID + ".id_HOST_123456789_9"}},
"scope": &ref.ReferenceParameter{ParameterReference: parameter.ParameterReference{Property: baseParamID + ".id_HOST_123456789"}},
"extractedIDs": value.New(map[string]string{
"id_HOST_123456789_9": "HOST-123456789.9",
"id_HOST_123456789": "HOST-123456789",
}),
},
},
},
},
},
{
"invalid param key chars (dot,hyphen) are removed from scope parameters",
project.ConfigsPerType{
"test-type": []config.Config{
{
Template: template.NewInMemoryTemplate("test-tmpl", "{}"),
Parameters: config.Parameters{
"scope": value.New("my.magic.metric-key"),
},
},
},
},
project.ConfigsPerType{
"test-type": []config.Config{
{
Template: template.NewInMemoryTemplate("test-tmpl", "{}"),
Parameters: config.Parameters{
"scope": &ref.ReferenceParameter{ParameterReference: parameter.ParameterReference{Property: baseParamID + ".id_my_magic_metric_key"}},
"extractedIDs": value.New(map[string]string{
"id_my_magic_metric_key": "my.magic.metric-key",
}),
},
},
Expand Down

0 comments on commit 46fff06

Please sign in to comment.