@@ -17,6 +17,7 @@ package librarian
1717import (
1818 "testing"
1919
20+ "github.com/google/go-cmp/cmp"
2021 "github.com/googleapis/librarian/internal/config"
2122)
2223
@@ -52,3 +53,128 @@ func TestNewTagAndReleaseRunner(t *testing.T) {
5253 })
5354 }
5455}
56+
57+ func TestParsePullRequestBody (t * testing.T ) {
58+ tests := []struct {
59+ name string
60+ body string
61+ want []libraryRelease
62+ }{
63+ {
64+ name : "single library" ,
65+ body : `
66+ Librarian Version: v0.2.0
67+ Language Image: image
68+
69+ <details><summary>google-cloud-storage: 1.2.3</summary>
70+
71+ [1.2.3](https://github.com/googleapis/google-cloud-go/compare/google-cloud-storage-v1.2.2...google-cloud-storage-v1.2.3) (2025-08-15)
72+
73+ ### Features
74+
75+ * Add new feature ([abcdef1](https://github.com/googleapis/google-cloud-go/commit/abcdef1))
76+
77+ </details>` ,
78+ want : []libraryRelease {
79+ {
80+ Version : "1.2.3" ,
81+ Library : "google-cloud-storage" ,
82+ Body : `[1.2.3](https://github.com/googleapis/google-cloud-go/compare/google-cloud-storage-v1.2.2...google-cloud-storage-v1.2.3) (2025-08-15)
83+
84+ ### Features
85+
86+ * Add new feature ([abcdef1](https://github.com/googleapis/google-cloud-go/commit/abcdef1))` ,
87+ },
88+ },
89+ },
90+ {
91+ name : "multiple libraries" ,
92+ body : `
93+ Librarian Version: 1.2.3
94+ Language Image: gcr.io/test/image:latest
95+
96+ <details><summary>library-one: 1.0.0</summary>
97+
98+ [1.0.0](https://github.com/googleapis/repo/compare/library-one-v0.9.0...library-one-v1.0.0) (2025-08-15)
99+
100+ ### Features
101+
102+ * some feature ([1234567](https://github.com/googleapis/repo/commit/1234567))
103+
104+ </details>
105+
106+ <details><summary>another-library-name: 2.3.4</summary>
107+
108+ [2.3.4](https://github.com/googleapis/repo/compare/another-library-name-v2.3.3...another-library-name-v2.3.4) (2025-08-15)
109+
110+ ### Bug Fixes
111+
112+ * some bug fix ([abcdefg](https://github.com/googleapis/repo/commit/abcdefg))
113+
114+ </details>` ,
115+ want : []libraryRelease {
116+ {
117+ Version : "1.0.0" ,
118+ Library : "library-one" ,
119+ Body : `[1.0.0](https://github.com/googleapis/repo/compare/library-one-v0.9.0...library-one-v1.0.0) (2025-08-15)
120+
121+ ### Features
122+
123+ * some feature ([1234567](https://github.com/googleapis/repo/commit/1234567))` ,
124+ },
125+ {
126+ Version : "2.3.4" ,
127+ Library : "another-library-name" ,
128+ Body : `[2.3.4](https://github.com/googleapis/repo/compare/another-library-name-v2.3.3...another-library-name-v2.3.4) (2025-08-15)
129+
130+ ### Bug Fixes
131+
132+ * some bug fix ([abcdefg](https://github.com/googleapis/repo/commit/abcdefg))` ,
133+ },
134+ },
135+ },
136+ {
137+ name : "empty body" ,
138+ body : "" ,
139+ want : nil ,
140+ },
141+ {
142+ name : "malformed summary" ,
143+ body : `
144+ Librarian Version: 1.2.3
145+ Language Image: gcr.io/test/image:latest
146+
147+ <details><summary>no-version-here</summary>
148+
149+ some content
150+
151+ </details>` ,
152+ want : nil ,
153+ },
154+ {
155+ name : "v prefix in version" ,
156+ body : `
157+ <details><summary>google-cloud-storage: v1.2.3</summary>
158+
159+ [v1.2.3](https://github.com/googleapis/google-cloud-go/compare/google-cloud-storage-v1.2.2...google-cloud-storage-v1.2.3) (2025-08-15)
160+
161+ </details>` ,
162+ want : []libraryRelease {
163+ {
164+ Version : "v1.2.3" ,
165+ Library : "google-cloud-storage" ,
166+ Body : "[v1.2.3](https://github.com/googleapis/google-cloud-go/compare/google-cloud-storage-v1.2.2...google-cloud-storage-v1.2.3) (2025-08-15)" ,
167+ },
168+ },
169+ },
170+ }
171+
172+ for _ , tt := range tests {
173+ t .Run (tt .name , func (t * testing.T ) {
174+ got := parsePullRequestBody (tt .body )
175+ if diff := cmp .Diff (tt .want , got ); diff != "" {
176+ t .Errorf ("ParsePullRequestBody() mismatch (-want +got):\n %s" , diff )
177+ }
178+ })
179+ }
180+ }
0 commit comments