Skip to content

Commit ef51031

Browse files
authored
feat(testing): add e2e test for release init workflow (#2033)
This PR adds E2E test for the release init workflow. The tests verify that the command updates the state.yaml file correctly by comparing it with golden files.
1 parent 4d30998 commit ef51031

File tree

6 files changed

+415
-15
lines changed

6 files changed

+415
-15
lines changed

e2e_test.go

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,152 @@ func TestRunGenerate_MultipleLibraries(t *testing.T) {
394394
}
395395
}
396396

397+
func TestReleaseInit(t *testing.T) {
398+
t.Parallel()
399+
for _, test := range []struct {
400+
name string
401+
initialRepoStateDir string
402+
updatedState string
403+
wantChangelog string
404+
libraryID string
405+
wantErr bool
406+
}{
407+
{
408+
name: "runs successfully",
409+
initialRepoStateDir: "testdata/e2e/release/init/repo_init",
410+
updatedState: "testdata/e2e/release/init/updated-state.yaml",
411+
wantChangelog: "testdata/e2e/release/init/CHANGELOG.md",
412+
libraryID: "go-google-cloud-pubsub-v1",
413+
},
414+
} {
415+
t.Run(test.name, func(t *testing.T) {
416+
workRoot := t.TempDir()
417+
repo := t.TempDir()
418+
419+
if err := initRepo(t, repo, test.initialRepoStateDir); err != nil {
420+
t.Fatalf("prepare test error = %v", err)
421+
}
422+
runGit(t, repo, "tag", "go-google-cloud-pubsub-v1-1.0.0")
423+
// Add a new commit to simulate a change.
424+
newFilePath := filepath.Join(repo, "google-cloud-pubsub/v1", "new-file.txt")
425+
if err := os.WriteFile(newFilePath, []byte("new file"), 0644); err != nil {
426+
t.Fatal(err)
427+
}
428+
runGit(t, repo, "add", newFilePath)
429+
commitMsg := `
430+
chore: Update generation configuration at Tue Aug 26 02:31:23 UTC 2025 (#11734)
431+
432+
This pull request is generated with proto changes between
433+
[googleapis/googleapis@525c95a](https://github.com/googleapis/googleapis/commit/525c95a7a122ec2869ae06cd02fa5013819463f6)
434+
(exclusive) and
435+
[googleapis/googleapis@b738e78](https://github.com/googleapis/googleapis/commit/b738e78ed63effb7d199ed2d61c9e03291b6077f)
436+
(inclusive).
437+
438+
BEGIN_COMMIT_OVERRIDE
439+
BEGIN_NESTED_COMMIT
440+
feat: [texttospeech] Support promptable voices by specifying a model
441+
name and a prompt
442+
feat: [texttospeech] Add enum value M4A to enum AudioEncoding
443+
docs: [texttospeech] A comment for method 'StreamingSynthesize' in
444+
service 'TextToSpeech' is changed
445+
docs: [texttospeech] A comment for enum value
446+
'AUDIO_ENCODING_UNSPECIFIED' in enum 'AudioEncoding' is changed
447+
docs: [texttospeech] A comment for enum value 'OGG_OPUS' in enum
448+
'AudioEncoding' is changed
449+
docs: [texttospeech] A comment for enum value 'PCM' in enum
450+
'AudioEncoding' is changed
451+
docs: [texttospeech] A comment for field 'low_latency_journey_synthesis'
452+
in message '.google.cloud.texttospeech.v1beta1.AdvancedVoiceOptions' is
453+
changed
454+
docs: [texttospeech] A comment for enum value 'PHONETIC_ENCODING_IPA' in
455+
enum 'PhoneticEncoding' is changed
456+
docs: [texttospeech] A comment for enum value
457+
'PHONETIC_ENCODING_X_SAMPA' in enum 'PhoneticEncoding' is changed
458+
docs: [texttospeech] A comment for field 'phrase' in message
459+
'.google.cloud.texttospeech.v1beta1.CustomPronunciationParams' is
460+
changed
461+
docs: [texttospeech] A comment for field 'pronunciations' in message
462+
'.google.cloud.texttospeech.v1beta1.CustomPronunciations' is changed
463+
docs: [texttospeech] A comment for message 'MultiSpeakerMarkup' is
464+
changed
465+
docs: [texttospeech] A comment for field 'custom_pronunciations' in
466+
message '.google.cloud.texttospeech.v1beta1.SynthesisInput' is changed
467+
docs: [texttospeech] A comment for field 'voice_clone' in message
468+
'.google.cloud.texttospeech.v1beta1.VoiceSelectionParams' is changed
469+
docs: [texttospeech] A comment for field 'speaking_rate' in message
470+
'.google.cloud.texttospeech.v1beta1.AudioConfig' is changed
471+
docs: [texttospeech] A comment for field 'audio_encoding' in message
472+
'.google.cloud.texttospeech.v1beta1.StreamingAudioConfig' is changed
473+
docs: [texttospeech] A comment for field 'text' in message
474+
'.google.cloud.texttospeech.v1beta1.StreamingSynthesisInput' is changed
475+
476+
PiperOrigin-RevId: 799242210
477+
478+
Source Link:
479+
[googleapis/googleapis@b738e78](https://github.com/googleapis/googleapis/commit/b738e78ed63effb7d199ed2d61c9e03291b6077f)
480+
END_NESTED_COMMIT
481+
END_COMMIT_OVERRIDE
482+
`
483+
runGit(t, repo, "commit", "-m", commitMsg)
484+
runGit(t, repo, "log", "--oneline", "go-google-cloud-pubsub-v1-1.0.0..HEAD", "--", "google-cloud-pubsub/v1")
485+
486+
cmd := exec.Command(
487+
"go",
488+
"run",
489+
"github.com/googleapis/librarian/cmd/librarian",
490+
"release",
491+
"init",
492+
fmt.Sprintf("--repo=%s", repo),
493+
fmt.Sprintf("--output=%s", workRoot),
494+
fmt.Sprintf("--library=%s", test.libraryID),
495+
)
496+
cmd.Stderr = os.Stderr
497+
cmd.Stdout = os.Stdout
498+
err := cmd.Run()
499+
if err != nil {
500+
t.Fatalf("Failed to run release init: %v", err)
501+
}
502+
503+
// Verify the state.yaml file content
504+
outputDir := filepath.Join(workRoot, "output")
505+
t.Logf("Checking for output file in: %s", filepath.Join(outputDir, ".librarian", "state.yaml"))
506+
gotBytes, err := os.ReadFile(filepath.Join(outputDir, ".librarian", "state.yaml"))
507+
if err != nil {
508+
t.Fatalf("Failed to read updated state.yaml from output directory: %v", err)
509+
}
510+
wantBytes, readErr := os.ReadFile(test.updatedState)
511+
if readErr != nil {
512+
t.Fatalf("Failed to read expected state for comparison: %v", readErr)
513+
}
514+
var gotState *config.LibrarianState
515+
if err := yaml.Unmarshal(gotBytes, &gotState); err != nil {
516+
t.Fatalf("Failed to unmarshal configure response file: %v", err)
517+
}
518+
var wantState *config.LibrarianState
519+
if err := yaml.Unmarshal(wantBytes, &wantState); err != nil {
520+
t.Fatalf("Failed to unmarshal expected state: %v", err)
521+
}
522+
523+
if diff := cmp.Diff(wantState, gotState); diff != "" {
524+
t.Fatalf("Generated yaml mismatch (-want +got): %s", diff)
525+
}
526+
527+
// Verify the CHANGELOG.md file content
528+
gotChangelog, err := os.ReadFile(filepath.Join(outputDir, "google-cloud-pubsub/v1", "CHANGELOG.md"))
529+
if err != nil {
530+
t.Fatalf("Failed to read CHANGELOG.md from output directory: %v", err)
531+
}
532+
wantChangelogBytes, err := os.ReadFile(test.wantChangelog)
533+
if err != nil {
534+
t.Fatalf("Failed to read expected changelog for comparison: %v", err)
535+
}
536+
if diff := cmp.Diff(string(wantChangelogBytes), string(gotChangelog)); diff != "" {
537+
t.Fatalf("Generated changelog mismatch (-want +got): %s", diff)
538+
}
539+
})
540+
}
541+
}
542+
397543
// initRepo initiates a git repo in the given directory, copy
398544
// files from source directory and create a commit.
399545
func initRepo(t *testing.T, dir, source string) error {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## 1.1.0
2+
3+
- feat: [texttospeech] Support promptable voices by specifying a model name and a prompt
4+
- feat: [texttospeech] Add enum value M4A to enum AudioEncoding
5+
- docs: [texttospeech] A comment for method 'StreamingSynthesize' in service 'TextToSpeech' is changed
6+
- docs: [texttospeech] A comment for enum value 'AUDIO_ENCODING_UNSPECIFIED' in enum 'AudioEncoding' is changed
7+
- docs: [texttospeech] A comment for enum value 'OGG_OPUS' in enum 'AudioEncoding' is changed
8+
- docs: [texttospeech] A comment for enum value 'PCM' in enum 'AudioEncoding' is changed
9+
- docs: [texttospeech] A comment for field 'low_latency_journey_synthesis' in message '.google.cloud.texttospeech.v1beta1.AdvancedVoiceOptions' is changed
10+
- docs: [texttospeech] A comment for enum value 'PHONETIC_ENCODING_IPA' in enum 'PhoneticEncoding' is changed
11+
- docs: [texttospeech] A comment for enum value 'PHONETIC_ENCODING_X_SAMPA' in enum 'PhoneticEncoding' is changed
12+
- docs: [texttospeech] A comment for field 'phrase' in message '.google.cloud.texttospeech.v1beta1.CustomPronunciationParams' is changed
13+
- docs: [texttospeech] A comment for field 'pronunciations' in message '.google.cloud.texttospeech.v1beta1.CustomPronunciations' is changed
14+
- docs: [texttospeech] A comment for message 'MultiSpeakerMarkup' is changed
15+
- docs: [texttospeech] A comment for field 'custom_pronunciations' in message '.google.cloud.texttospeech.v1beta1.SynthesisInput' is changed
16+
- docs: [texttospeech] A comment for field 'voice_clone' in message '.google.cloud.texttospeech.v1beta1.VoiceSelectionParams' is changed
17+
- docs: [texttospeech] A comment for field 'speaking_rate' in message '.google.cloud.texttospeech.v1beta1.AudioConfig' is changed
18+
- docs: [texttospeech] A comment for field 'audio_encoding' in message '.google.cloud.texttospeech.v1beta1.StreamingAudioConfig' is changed
19+
- docs: [texttospeech] A comment for field 'text' in message '.google.cloud.texttospeech.v1beta1.StreamingSynthesisInput' is changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
image: test-image:latest
2+
libraries:
3+
- id: go-google-cloud-pubsub-v1
4+
version: 1.0.0
5+
apis:
6+
- path: google/cloud/pubsub/v1
7+
source_roots:
8+
- google-cloud-pubsub/v1
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package pubsub
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
image: test-image:latest
2+
libraries:
3+
- id: go-google-cloud-pubsub-v1
4+
version: 1.1.0
5+
apis:
6+
- path: google/cloud/pubsub/v1
7+
source_roots:
8+
- google-cloud-pubsub/v1

0 commit comments

Comments
 (0)