Skip to content

Commit 1328cd1

Browse files
authored
fix(devtools/cmd/migrate-sidekick): fix mismatch in newline handling for documentationoverrides (#3341)
Add on a temp fix on top of the previous fix #3284. This fix tries to align the expected format for `documentation_overrides` for `google-cloud-orgpolicy-v1`. This is a brittle change, but as we don't expect new `documentation_overrides` in the next few days and this is a one time migration, it should be acceptable. Verified locally after this change, `librarian generate google-cloud-orgpolicy-v1` produces no diff. And the only diff it produced for librarian.yaml is the following: ``` --- a/librarian.yaml +++ b/librarian.yaml @@ -1084,14 +1084,16 @@ libraries: title_override: Organization Policy Types documentation_overrides: - id: .google.cloud.orgpolicy.v1.Policy.ListPolicy - match: 'Ancestry subtrees must be in one of the following formats:' + match: | + Ancestry subtrees must be in one of the following formats: replace: | - + Ancestry subtrees must be in one of the following formats: - id: .google.cloud.orgpolicy.v1.Policy.ListPolicy - match: The `supports_under` field of the associated `Constraint` defines whether + match: | + The `supports_under` field of the associated `Constraint` defines whether replace: | - + The `supports_under` field of the associated `Constraint` defines whether ``` Additional context about this fix: #3330 (comment) Fix #3330
1 parent 3137642 commit 1328cd1

2 files changed

Lines changed: 18 additions & 11 deletions

File tree

devtools/cmd/migrate-sidekick/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -807,9 +807,9 @@ func fixDocumentOverrideNewLines(yamlFile string, config *config.Config) error {
807807
lookupKey := currentID + "|" + currentVal
808808

809809
if data, ok := lookup[lookupKey]; ok {
810-
if strings.Contains(data.Match, "\n") {
810+
// brittle: if replace has new lines, match has new line at start
811+
if strings.Contains(data.Replace, "\n") {
811812
newLines = append(newLines, fmt.Sprintf("%smatch: |", indent))
812-
newLines = append(newLines, "") // Leading newline
813813
newLines = append(newLines, indent+" "+strings.TrimSpace(data.Match))
814814
} else {
815815
newLines = append(newLines, line) // Keep original if no newline

devtools/cmd/migrate-sidekick/main_test.go

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -789,15 +789,17 @@ func TestBuildConfig(t *testing.T) {
789789

790790
func TestRunMigrateCommand(t *testing.T) {
791791
for _, test := range []struct {
792-
name string
793-
path string
794-
wantErr error
795-
checkDocumentOverrideValues []string
792+
name string
793+
path string
794+
wantErr error
795+
checkDocumentOverrideReplace []string
796+
checkDocumentOverrideMatch []string
796797
}{
797798
{
798-
name: "success",
799-
path: "testdata/run/success",
800-
checkDocumentOverrideValues: []string{"example replace", "\nAncestry subtrees must be in one of the following formats:\n"},
799+
name: "success",
800+
path: "testdata/run/success",
801+
checkDocumentOverrideMatch: []string{"example match", "Ancestry subtrees must be in one of the following formats:\n"},
802+
checkDocumentOverrideReplace: []string{"example replace", "\nAncestry subtrees must be in one of the following formats:\n"},
801803
},
802804
{
803805
name: "tidy_command_fails",
@@ -840,12 +842,17 @@ func TestRunMigrateCommand(t *testing.T) {
840842
if len(librarianConfig.Libraries) != 1 {
841843
t.Fatalf("librarian yaml does not contain library")
842844
}
843-
if len(test.checkDocumentOverrideValues) > 0 {
844-
for index, expected := range test.checkDocumentOverrideValues {
845+
if len(test.checkDocumentOverrideReplace) > 0 {
846+
for index, expected := range test.checkDocumentOverrideReplace {
845847
got := librarianConfig.Libraries[0].Rust.DocumentationOverrides[index].Replace
846848
if got != expected {
847849
t.Fatalf("expected checkDocumentOverrideValue: %s got: %s", expected, got)
848850
}
851+
gotMatch := librarianConfig.Libraries[0].Rust.DocumentationOverrides[index].Match
852+
if expected := test.checkDocumentOverrideMatch[index]; gotMatch != expected {
853+
t.Fatalf("expected checkDocumentOverrideMatch: %s got: %s", expected, gotMatch)
854+
}
855+
849856
}
850857
}
851858
if librarianConfig.Release == nil {

0 commit comments

Comments
 (0)