Skip to content

Commit 504ecbe

Browse files
authored
feat(testing): Refactor and add validation to release init E2E test (#2298)
The primary motivations for this change were: 1. To add a new test case simulating a real-world Python library release. 2. To add a new test case simulating a real-world Go library release. 3. To introduce a permanent contract test that validates the `librarian` tool's output, specifically to prevent regressions of the bug described in issue #2254, where commits were associated with the wrong package. Part of #2254 Fixes #2289
1 parent 7239558 commit 504ecbe

File tree

15 files changed

+322
-81
lines changed

15 files changed

+322
-81
lines changed

e2e_test.go

Lines changed: 68 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -429,35 +429,64 @@ func TestRunGenerate_MultipleLibraries(t *testing.T) {
429429
func TestReleaseInit(t *testing.T) {
430430
t.Parallel()
431431
for _, test := range []struct {
432-
name string
433-
initialRepoStateDir string
434-
updatedState string
435-
wantChangelog string
436-
libraryID string
437-
push bool
438-
wantErr bool
432+
name string
433+
testDataDir string
434+
libraryID string
435+
changePath string
436+
tagID string
437+
tagVersion string
438+
tagFormat string
439+
push bool
440+
wantErr bool
439441
}{
440442
{
441-
name: "runs successfully without push",
442-
initialRepoStateDir: "testdata/e2e/release/init/repo_init",
443-
updatedState: "testdata/e2e/release/init/updated-state.yaml",
444-
wantChangelog: "testdata/e2e/release/init/CHANGELOG.md",
445-
libraryID: "go-google-cloud-pubsub-v1",
443+
name: "release with multiple commits",
444+
testDataDir: "testdata/e2e/release/init/multiple_commits",
445+
libraryID: "go-google-cloud-pubsub-v1",
446+
changePath: "google-cloud-pubsub/v1",
447+
tagID: "go-google-cloud-pubsub-v1",
448+
tagVersion: "1.0.0",
449+
tagFormat: "%s/v%s",
450+
},
451+
{
452+
name: "release with multiple commits with push",
453+
testDataDir: "testdata/e2e/release/init/multiple_commits",
454+
libraryID: "go-google-cloud-pubsub-v1",
455+
changePath: "google-cloud-pubsub/v1",
456+
tagID: "go-google-cloud-pubsub-v1",
457+
tagVersion: "1.0.0",
458+
tagFormat: "%s/v%s",
459+
push: true,
460+
},
461+
{
462+
name: "release with multiple nested commits",
463+
testDataDir: "testdata/e2e/release/init/multiple_nested_commits",
464+
libraryID: "python-google-cloud-video-live-stream-v1",
465+
changePath: "packages/google-cloud-video-live-stream",
466+
tagID: "python-google-cloud-video-live-stream-v1",
467+
tagVersion: "v1.12.0",
468+
tagFormat: "%s-%s", // Format for {id}-{version}
446469
},
447470
{
448-
name: "runs successfully with push",
449-
initialRepoStateDir: "testdata/e2e/release/init/repo_init",
450-
updatedState: "testdata/e2e/release/init/updated-state.yaml",
451-
wantChangelog: "testdata/e2e/release/init/CHANGELOG.md",
452-
libraryID: "go-google-cloud-pubsub-v1",
453-
push: true, // Enable --push for this case
471+
name: "release with single commit",
472+
testDataDir: "testdata/e2e/release/init/single_commit",
473+
libraryID: "dlp",
474+
changePath: "dlp",
475+
tagID: "dlp",
476+
tagVersion: "1.24.0",
477+
tagFormat: "%s/v%s",
454478
},
455479
} {
456480
t.Run(test.name, func(t *testing.T) {
457481
workRoot := t.TempDir()
458482
repo := t.TempDir()
459483

460-
if err := initRepo(t, repo, test.initialRepoStateDir); err != nil {
484+
initialRepoStateDir := filepath.Join(test.testDataDir, "repo_init")
485+
updatedState := filepath.Join(test.testDataDir, "state.yaml")
486+
wantChangelog := filepath.Join(test.testDataDir, "CHANGELOG.md")
487+
commitMsgPath := filepath.Join(test.testDataDir, "commit_msg.txt")
488+
489+
if err := initRepo(t, repo, initialRepoStateDir); err != nil {
461490
t.Fatalf("prepare test error = %v", err)
462491
}
463492

@@ -471,51 +500,26 @@ func TestReleaseInit(t *testing.T) {
471500
runGit(t, repo, "remote", "set-url", "origin", bareRepoDir)
472501
}
473502

474-
runGit(t, repo, "tag", "go-google-cloud-pubsub-v1-1.0.0")
503+
// Dynamically create the tag based on the format string
504+
tagName := fmt.Sprintf(test.tagFormat, test.tagID, test.tagVersion)
505+
runGit(t, repo, "tag", tagName)
506+
475507
// Add a new commit to simulate a change.
476-
newFilePath := filepath.Join(repo, "google-cloud-pubsub/v1", "new-file.txt")
508+
newFilePath := filepath.Join(repo, test.changePath, "new-file.txt")
509+
if err := os.MkdirAll(filepath.Dir(newFilePath), 0755); err != nil {
510+
t.Fatalf("Failed to create directory for new file: %v", err)
511+
}
477512
if err := os.WriteFile(newFilePath, []byte("new file"), 0644); err != nil {
478513
t.Fatal(err)
479514
}
480515
runGit(t, repo, "add", newFilePath)
481-
commitMsg := `
482-
chore: Update generation configuration at Tue Aug 26 02:31:23 UTC 2025 (#11734)
483-
484-
This pull request is generated with proto changes between
485-
[googleapis/googleapis@525c95a](https://github.com/googleapis/googleapis/commit/525c95a7a122ec2869ae06cd02fa5013819463f6)
486-
(exclusive) and
487-
[googleapis/googleapis@b738e78](https://github.com/googleapis/googleapis/commit/b738e78ed63effb7d199ed2d61c9e03291b6077f)
488-
(inclusive).
489-
490-
BEGIN_COMMIT_OVERRIDE
491-
BEGIN_NESTED_COMMIT
492-
feat: [go-google-cloud-pubsub-v1] Support promptable voices by specifying a model name and a prompt
493-
feat: [go-google-cloud-pubsub-v1] Add enum value M4A to enum AudioEncoding
494-
docs: [go-google-cloud-pubsub-v1] A comment for method 'StreamingSynthesize' in service 'TextToSpeech' is changed
495-
docs: [go-google-cloud-pubsub-v1] A comment for enum value 'AUDIO_ENCODING_UNSPECIFIED' in enum 'AudioEncoding' is changed
496-
docs: [go-google-cloud-pubsub-v1] A comment for enum value 'OGG_OPUS' in enum 'AudioEncoding' is changed
497-
docs: [go-google-cloud-pubsub-v1] A comment for enum value 'PCM' in enum 'AudioEncoding' is changed
498-
docs: [go-google-cloud-pubsub-v1] A comment for field 'low_latency_journey_synthesis' in message '.google.cloud.texttospeech.v1beta1.AdvancedVoiceOptions' is changed
499-
docs: [go-google-cloud-pubsub-v1] A comment for enum value 'PHONETIC_ENCODING_IPA' in enum 'PhoneticEncoding' is changed
500-
docs: [go-google-cloud-pubsub-v1] A comment for enum value 'PHONETIC_ENCODING_X_SAMPA' in enum 'PhoneticEncoding' is changed
501-
docs: [go-google-cloud-pubsub-v1] A comment for field 'phrase' in message '.google.cloud.texttospeech.v1beta1.CustomPronunciationParams' is changed
502-
docs: [go-google-cloud-pubsub-v1] A comment for field 'pronunciations' in message '.google.cloud.texttospeech.v1beta1.CustomPronunciations' is changed
503-
docs: [go-google-cloud-pubsub-v1] A comment for message 'MultiSpeakerMarkup' is changed
504-
docs: [go-google-cloud-pubsub-v1] A comment for field 'custom_pronunciations' in message '.google.cloud.texttospeech.v1beta1.SynthesisInput' is changed
505-
docs: [go-google-cloud-pubsub-v1] A comment for field 'voice_clone' in message '.google.cloud.texttospeech.v1beta1.VoiceSelectionParams' is changed
506-
docs: [go-google-cloud-pubsub-v1] A comment for field 'speaking_rate' in message '.google.cloud.texttospeech.v1beta1.AudioConfig' is changed
507-
docs: [go-google-cloud-pubsub-v1] A comment for field 'audio_encoding' in message '.google.cloud.texttospeech.v1beta1.StreamingAudioConfig' is changed
508-
docs: [go-google-cloud-pubsub-v1] A comment for field 'text' in message '.google.cloud.texttospeech.v1beta1.StreamingSynthesisInput' is changed
509-
510-
PiperOrigin-RevId: 799242210
511-
512-
Source Link:
513-
[googleapis/googleapis@b738e78](https://github.com/googleapis/googleapis/commit/b738e78ed63effb7d199ed2d61c9e03291b6077f)
514-
END_NESTED_COMMIT
515-
END_COMMIT_OVERRIDE
516-
`
516+
commitMsgBytes, err := os.ReadFile(commitMsgPath)
517+
if err != nil {
518+
t.Fatalf("Failed to read commit message file: %v", err)
519+
}
520+
commitMsg := string(commitMsgBytes)
517521
runGit(t, repo, "commit", "-m", commitMsg)
518-
runGit(t, repo, "log", "--oneline", "go-google-cloud-pubsub-v1-1.0.0..HEAD", "--", "google-cloud-pubsub/v1")
522+
runGit(t, repo, "log", "--oneline", fmt.Sprintf("%s..HEAD", tagName), "--", test.changePath)
519523

520524
server := newMockGitHubServer(t, "release")
521525
defer server.Close()
@@ -540,8 +544,7 @@ END_COMMIT_OVERRIDE
540544
cmd.Env = append(cmd.Env, "LIBRARIAN_GITHUB_BASE_URL="+server.URL)
541545
cmd.Stderr = os.Stderr
542546
cmd.Stdout = os.Stdout
543-
err := cmd.Run()
544-
if err != nil {
547+
if err := cmd.Run(); err != nil {
545548
t.Fatalf("Failed to run release init: %v", err)
546549
}
547550

@@ -552,7 +555,7 @@ END_COMMIT_OVERRIDE
552555
if err != nil {
553556
t.Fatalf("Failed to read updated state.yaml from output directory: %v", err)
554557
}
555-
wantBytes, readErr := os.ReadFile(test.updatedState)
558+
wantBytes, readErr := os.ReadFile(updatedState)
556559
if readErr != nil {
557560
t.Fatalf("Failed to read expected state for comparison: %v", readErr)
558561
}
@@ -565,16 +568,17 @@ END_COMMIT_OVERRIDE
565568
t.Fatalf("Failed to unmarshal expected state: %v", err)
566569
}
567570

568-
if diff := cmp.Diff(wantState, gotState); diff != "" {
571+
// Use cmpopts.IgnoreFields to ignore the dynamic commit hash.
572+
if diff := cmp.Diff(wantState, gotState, cmpopts.IgnoreFields(config.LibraryState{}, "LastGeneratedCommit")); diff != "" {
569573
t.Fatalf("Generated yaml mismatch (-want +got): %s", diff)
570574
}
571575

572576
// Verify the CHANGELOG.md file content
573-
gotChangelog, err := os.ReadFile(filepath.Join(outputDir, "google-cloud-pubsub/v1", "CHANGELOG.md"))
577+
gotChangelog, err := os.ReadFile(filepath.Join(outputDir, test.changePath, "CHANGELOG.md"))
574578
if err != nil {
575579
t.Fatalf("Failed to read CHANGELOG.md from output directory: %v", err)
576580
}
577-
wantChangelogBytes, err := os.ReadFile(test.wantChangelog)
581+
wantChangelogBytes, err := os.ReadFile(wantChangelog)
578582
if err != nil {
579583
t.Fatalf("Failed to read expected changelog for comparison: %v", err)
580584
}

testdata/e2e/release/init/CHANGELOG.md renamed to testdata/e2e/release/init/multiple_commits/CHANGELOG.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
- docs: [go-google-cloud-pubsub-v1] A comment for enum value 'AUDIO_ENCODING_UNSPECIFIED' in enum 'AudioEncoding' is changed
77
- docs: [go-google-cloud-pubsub-v1] A comment for enum value 'OGG_OPUS' in enum 'AudioEncoding' is changed
88
- docs: [go-google-cloud-pubsub-v1] A comment for enum value 'PCM' in enum 'AudioEncoding' is changed
9-
- docs: [go-google-cloud-pubsub-v1] A comment for field 'low_latency_journey_synthesis' in message '.google.cloud.texttospeech.v1beta1.AdvancedVoiceOptions' is changed
9+
- docs: [go-google-cloud-pubsub-v1] A comment for field 'low_latency_journey_synthesis' in message '.google.cloud.go-google-cloud-pubsub-v1.v1beta1.AdvancedVoiceOptions' is changed
1010
- docs: [go-google-cloud-pubsub-v1] A comment for enum value 'PHONETIC_ENCODING_IPA' in enum 'PhoneticEncoding' is changed
1111
- docs: [go-google-cloud-pubsub-v1] A comment for enum value 'PHONETIC_ENCODING_X_SAMPA' in enum 'PhoneticEncoding' is changed
12-
- docs: [go-google-cloud-pubsub-v1] A comment for field 'phrase' in message '.google.cloud.texttospeech.v1beta1.CustomPronunciationParams' is changed
13-
- docs: [go-google-cloud-pubsub-v1] A comment for field 'pronunciations' in message '.google.cloud.texttospeech.v1beta1.CustomPronunciations' is changed
12+
- docs: [go-google-cloud-pubsub-v1] A comment for field 'phrase' in message '.google.cloud.go-google-cloud-pubsub-v1.v1beta1.CustomPronunciationParams' is changed
13+
- docs: [go-google-cloud-pubsub-v1] A comment for field 'pronunciations' in message '.google.cloud.go-google-cloud-pubsub-v1.v1beta1.CustomPronunciations' is changed
1414
- docs: [go-google-cloud-pubsub-v1] A comment for message 'MultiSpeakerMarkup' is changed
15-
- docs: [go-google-cloud-pubsub-v1] A comment for field 'custom_pronunciations' in message '.google.cloud.texttospeech.v1beta1.SynthesisInput' is changed
16-
- docs: [go-google-cloud-pubsub-v1] A comment for field 'voice_clone' in message '.google.cloud.texttospeech.v1beta1.VoiceSelectionParams' is changed
17-
- docs: [go-google-cloud-pubsub-v1] A comment for field 'speaking_rate' in message '.google.cloud.texttospeech.v1beta1.AudioConfig' is changed
18-
- docs: [go-google-cloud-pubsub-v1] A comment for field 'audio_encoding' in message '.google.cloud.texttospeech.v1beta1.StreamingAudioConfig' is changed
19-
- docs: [go-google-cloud-pubsub-v1] A comment for field 'text' in message '.google.cloud.texttospeech.v1beta1.StreamingSynthesisInput' is changed
15+
- docs: [go-google-cloud-pubsub-v1] A comment for field 'custom_pronunciations' in message '.google.cloud.go-google-cloud-pubsub-v1.v1beta1.SynthesisInput' is changed
16+
- docs: [go-google-cloud-pubsub-v1] A comment for field 'voice_clone' in message '.google.cloud.go-google-cloud-pubsub-v1.v1beta1.VoiceSelectionParams' is changed
17+
- docs: [go-google-cloud-pubsub-v1] A comment for field 'speaking_rate' in message '.google.cloud.go-google-cloud-pubsub-v1.v1beta1.AudioConfig' is changed
18+
- docs: [go-google-cloud-pubsub-v1] A comment for field 'audio_encoding' in message '.google.cloud.go-google-cloud-pubsub-v1.v1beta1.StreamingAudioConfig' is changed
19+
- docs: [go-google-cloud-pubsub-v1] A comment for field 'text' in message '.google.cloud.go-google-cloud-pubsub-v1.v1beta1.StreamingSynthesisInput' is changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
chore: Update generation configuration at Tue Aug 26 02:31:23 UTC 2025 (#11734)
2+
3+
This pull request is generated with proto changes between
4+
[googleapis/googleapis@525c95a](https://github.com/googleapis/googleapis/commit/525c95a7a122ec2869ae06cd02fa5013819463f6)
5+
(exclusive) and
6+
[googleapis/googleapis@b738e78](https://github.com/googleapis/googleapis/commit/b738e78ed63effb7d199ed2d61c9e03291b6077f)
7+
(inclusive).
8+
9+
Librarian Version: v0.0.0-20250918210716-c3c71af9310a
10+
Language Image:
11+
us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/librarian-go:latest
12+
13+
BEGIN_COMMIT_OVERRIDE
14+
BEGIN_NESTED_COMMIT
15+
feat: [go-google-cloud-pubsub-v1] Support promptable voices by specifying a model name and a prompt
16+
feat: [go-google-cloud-pubsub-v1] Add enum value M4A to enum AudioEncoding
17+
docs: [go-google-cloud-pubsub-v1] A comment for method 'StreamingSynthesize' in service 'TextToSpeech' is changed
18+
docs: [go-google-cloud-pubsub-v1] A comment for enum value 'AUDIO_ENCODING_UNSPECIFIED' in enum 'AudioEncoding' is changed
19+
docs: [go-google-cloud-pubsub-v1] A comment for enum value 'OGG_OPUS' in enum 'AudioEncoding' is changed
20+
docs: [go-google-cloud-pubsub-v1] A comment for enum value 'PCM' in enum 'AudioEncoding' is changed
21+
docs: [go-google-cloud-pubsub-v1] A comment for field 'low_latency_journey_synthesis' in message '.google.cloud.go-google-cloud-pubsub-v1.v1beta1.AdvancedVoiceOptions' is changed
22+
docs: [go-google-cloud-pubsub-v1] A comment for enum value 'PHONETIC_ENCODING_IPA' in enum 'PhoneticEncoding' is changed
23+
docs: [go-google-cloud-pubsub-v1] A comment for enum value 'PHONETIC_ENCODING_X_SAMPA' in enum 'PhoneticEncoding' is changed
24+
docs: [go-google-cloud-pubsub-v1] A comment for field 'phrase' in message '.google.cloud.go-google-cloud-pubsub-v1.v1beta1.CustomPronunciationParams' is changed
25+
docs: [go-google-cloud-pubsub-v1] A comment for field 'pronunciations' in message '.google.cloud.go-google-cloud-pubsub-v1.v1beta1.CustomPronunciations' is changed
26+
docs: [go-google-cloud-pubsub-v1] A comment for message 'MultiSpeakerMarkup' is changed
27+
docs: [go-google-cloud-pubsub-v1] A comment for field 'custom_pronunciations' in message '.google.cloud.go-google-cloud-pubsub-v1.v1beta1.SynthesisInput' is changed
28+
docs: [go-google-cloud-pubsub-v1] A comment for field 'voice_clone' in message '.google.cloud.go-google-cloud-pubsub-v1.v1beta1.VoiceSelectionParams' is changed
29+
docs: [go-google-cloud-pubsub-v1] A comment for field 'speaking_rate' in message '.google.cloud.go-google-cloud-pubsub-v1.v1beta1.AudioConfig' is changed
30+
docs: [go-google-cloud-pubsub-v1] A comment for field 'audio_encoding' in message '.google.cloud.go-google-cloud-pubsub-v1.v1beta1.StreamingAudioConfig' is changed
31+
docs: [go-google-cloud-pubsub-v1] A comment for field 'text' in message '.google.cloud.go-google-cloud-pubsub-v1.v1beta1.StreamingSynthesisInput' is changed
32+
33+
PiperOrigin-RevId: 799242210
34+
35+
Source Link:
36+
[googleapis/googleapis@b738e78](https://github.com/googleapis/googleapis/commit/b738e78ed63effb7d199ed2d61c9e03291b6077f)
37+
END_NESTED_COMMIT
38+
END_COMMIT_OVERRIDE

testdata/e2e/release/init/repo_init/.librarian/state.yaml renamed to testdata/e2e/release/init/multiple_commits/repo_init/.librarian/state.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ libraries:
66
- path: google/cloud/pubsub/v1
77
source_roots:
88
- google-cloud-pubsub/v1
9+
tag_format: "{id}/v{version}"

testdata/e2e/release/init/updated-state.yaml renamed to testdata/e2e/release/init/multiple_commits/state.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ libraries:
66
- path: google/cloud/pubsub/v1
77
source_roots:
88
- google-cloud-pubsub/v1
9+
tag_format: "{id}/v{version}"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
## 1.13.0
2+
3+
- feat: [python-google-cloud-video-live-stream-v1] Added H.265 (HEVC) codec support
4+
- feat: [python-google-cloud-video-live-stream-v1] Added UHD (4k) resolution support
5+
- feat: [python-google-cloud-video-live-stream-v1] Added Auto Transcription support
6+
- feat: [python-google-cloud-video-live-stream-v1] Added StartDistribution/StopDistribution methods and Distribution/DistributionStream messages used for distributing live streams to external RTMP/SRT endpoints
7+
- feat: [python-google-cloud-video-live-stream-v1] Added PreviewInput method used for the low latency input monitoring
8+
- feat: [python-google-cloud-video-live-stream-v1] Added UpdateEncryptions event to perform key rotation without restarting a channel
9+
- docs: [python-google-cloud-video-live-stream-v1] Update requirements of resource ID fields to be more clear

0 commit comments

Comments
 (0)