@@ -142,6 +142,89 @@ func TestPlanHashUsesJCSCanonicalBytes(t *testing.T) {
142142 }
143143}
144144
145+ func TestBuildCommitMessageAppliesSubjectAndBodyModifiers (t * testing.T ) {
146+ ops := []Operation {{
147+ Verb : "set" ,
148+ Class : ClassIdempotent ,
149+ Descriptor : `set state.json $.status "done"` ,
150+ Value : `"done"` ,
151+ }}
152+
153+ got := buildCommitMessage (GlobalOptions {
154+ SubjectPrefix : "feat: " ,
155+ SubjectSuffix : " [skip ci]" ,
156+ }, ops )
157+ want := `feat: etch set state.json $.status "done" [skip ci]`
158+ if got != want {
159+ t .Fatalf ("message = %q, want %q" , got , want )
160+ }
161+
162+ got = buildCommitMessage (GlobalOptions {
163+ BodySuffix : "Refs: #1" ,
164+ }, ops )
165+ want = `etch set state.json $.status "done"` + "\n \n Refs: #1"
166+ if got != want {
167+ t .Fatalf ("message = %q, want %q" , got , want )
168+ }
169+ }
170+
171+ func TestBuildCommitMessageJoinsBodyModifiersWithGeneratedBody (t * testing.T ) {
172+ ops := []Operation {
173+ {
174+ Verb : "set" ,
175+ Class : ClassIdempotent ,
176+ Target : PlanTarget {Path : "state.json" },
177+ Descriptor : `set state.json $.status "done"` ,
178+ Value : `"done"` ,
179+ },
180+ {
181+ Verb : "delete" ,
182+ Class : ClassIdempotent ,
183+ Target : PlanTarget {Path : "state.json" },
184+ Descriptor : `delete state.json $.old` ,
185+ },
186+ }
187+
188+ got := buildCommitMessage (GlobalOptions {
189+ SubjectPrefix : "feat: " ,
190+ BodyPrefix : "Context: generated" ,
191+ BodySuffix : "\n \n Refs: #1" ,
192+ }, ops )
193+ want := strings .Join ([]string {
194+ "feat: etch: 2 changes in state.json" ,
195+ "" ,
196+ "Context: generated" ,
197+ "" ,
198+ "Changes:" ,
199+ `- set state.json $.status "done"` ,
200+ "- delete state.json $.old" ,
201+ "" ,
202+ "Refs: #1" ,
203+ }, "\n " )
204+ if got != want {
205+ t .Fatalf ("message = %q, want %q" , got , want )
206+ }
207+ }
208+
209+ func TestBuildCommitMessageSubjectModifiersAffectValueFallback (t * testing.T ) {
210+ ops := []Operation {{
211+ Verb : "set" ,
212+ Class : ClassIdempotent ,
213+ Descriptor : `set state.json $.status "1234567890123456789012345678901234567890"` ,
214+ Value : `"1234567890123456789012345678901234567890"` ,
215+ }}
216+
217+ got := buildCommitMessage (GlobalOptions {SubjectPrefix : "feat: " }, ops )
218+ want := strings .Join ([]string {
219+ "feat: etch set state.json $.status" ,
220+ "" ,
221+ `Value: "1234567890123456789012345678901234567890"` ,
222+ }, "\n " )
223+ if got != want {
224+ t .Fatalf ("message = %q, want %q" , got , want )
225+ }
226+ }
227+
145228func filepathJoin (elem ... string ) string {
146229 return filepath .Join (elem ... )
147230}
0 commit comments