-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
semconvgen: Add a flag for a path to a custom capitalizations file (#529
- Loading branch information
Showing
4 changed files
with
160 additions
and
19 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
.chloggen/528-semconvgen-flag-for-custom-capitalizations.yaml
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,16 @@ | ||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: enhancement | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. crosslink) | ||
component: semconvgen | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: "Add `--capitalizations-path` to allow users to add additional strings to the static capitalizations slice in generator.go" | ||
|
||
# One or more tracking issues related to the change | ||
issues: [528] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: |
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
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,83 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package main | ||
|
||
import ( | ||
"os" | ||
"reflect" | ||
"testing" | ||
) | ||
|
||
func TestCapitalizations(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
capitalizations string | ||
want []string | ||
}{ | ||
{ | ||
name: "No additional capitalizations", | ||
capitalizations: "", | ||
want: staticCapitalizations, | ||
}, | ||
{ | ||
name: "Some additional capitalizations", | ||
capitalizations: "ASPNETCore\nJVM", | ||
want: append(staticCapitalizations, "ASPNETCore", "JVM"), | ||
}, | ||
{ | ||
name: "Wrong separator for capitalizations", | ||
capitalizations: "ASPNETCore,JVM", | ||
want: append(staticCapitalizations, "ASPNETCore,JVM"), | ||
}, | ||
{ | ||
name: "Copius amounts of whitespace", | ||
capitalizations: ` | ||
ASPNETCore | ||
JVM | ||
`, | ||
want: append(staticCapitalizations, "ASPNETCore", "JVM"), | ||
}, | ||
} | ||
|
||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
tmpfile, err := os.CreateTemp("", "test") | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
defer os.Remove(tmpfile.Name()) | ||
|
||
if _, err = tmpfile.Write([]byte(tt.capitalizations)); err != nil { | ||
t.Fatal(err) | ||
} | ||
if err = tmpfile.Close(); err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
customCapitalizations, err := capitalizations(tmpfile.Name()) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
if !reflect.DeepEqual(customCapitalizations, tt.want) { | ||
t.Errorf("capitalizations() = %v, want %v", customCapitalizations, tt.want) | ||
} | ||
}) | ||
} | ||
} |