Skip to content

Commit 1483793

Browse files
infernus01zakisk
authored andcommitted
use ListProjectForks instead of creating forks in e2e test
Signed-off-by: Shubham Bhardwaj <shubbhar@redhat.com>
1 parent 440cf02 commit 1483793

File tree

1 file changed

+14
-29
lines changed

1 file changed

+14
-29
lines changed

test/gitlab_merge_request_test.go

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -709,32 +709,22 @@ func TestGitlabMergeRequestValidationErrorsFromFork(t *testing.T) {
709709
err = tgitlab.CreateCRD(ctx, originalProject, runcnx, opts, targetNS, nil)
710710
assert.NilError(t, err)
711711

712-
// Create a fork of the original project
713-
forkName := names.SimpleNameGenerator.RestrictLengthWithRandomSuffix("pac-fork-test")
714-
forkProject, _, err := glprovider.Client().Projects.ForkProject(opts.ProjectID, &clientGitlab.ForkProjectOptions{
715-
Name: &forkName,
716-
Path: &forkName,
717-
})
712+
// Get an existing fork of the original project
713+
projectForks, _, err := glprovider.Client().Projects.ListProjectForks(opts.ProjectID, &clientGitlab.ListProjectsOptions{})
718714
assert.NilError(t, err)
719-
runcnx.Clients.Log.Infof("Created fork project: %s (ID: %d) from original: %s (ID: %d)",
720-
forkProject.PathWithNamespace, forkProject.ID, originalProject.PathWithNamespace, originalProject.ID)
721715

722-
// Cleanup fork when test finishes
723-
defer func() {
724-
runcnx.Clients.Log.Infof("Cleaning up fork project: %d", forkProject.ID)
725-
_, err := glprovider.Client().Projects.DeleteProject(forkProject.ID, nil)
726-
if err != nil {
727-
runcnx.Clients.Log.Warnf("Failed to delete fork project: %v", err)
728-
}
729-
}()
716+
if len(projectForks) == 0 {
717+
t.Fatal("No forks available for testing fork scenario. This test requires at least one fork of the project.")
718+
}
730719

731-
// Wait sometime for fork to be fully ready
732-
time.Sleep(3 * time.Second)
720+
forkProject := projectForks[0] // Use the first available fork
721+
runcnx.Clients.Log.Infof("Using existing fork project: %s (ID: %d) from original: %s (ID: %d)",
722+
forkProject.PathWithNamespace, forkProject.ID, originalProject.PathWithNamespace, originalProject.ID)
733723

734724
// Commit invalid .tekton files to the fork
735725
entries, err := payload.GetEntries(map[string]string{
736726
".tekton/bad-yaml.yaml": "testdata/failures/bad-yaml.yaml",
737-
}, targetNS, forkProject.DefaultBranch,
727+
}, targetNS, originalProject.DefaultBranch,
738728
triggertype.PullRequest.String(), map[string]string{})
739729
assert.NilError(t, err)
740730

@@ -770,18 +760,13 @@ func TestGitlabMergeRequestValidationErrorsFromFork(t *testing.T) {
770760
originalProject.WebURL, mr.IID)
771761

772762
defer func() {
773-
// Close the MR and clean up branch
774-
runcnx.Clients.Log.Infof("Closing MR %d", mr.IID)
775-
_, _, err := glprovider.Client().MergeRequests.UpdateMergeRequest(originalProject.ID, mr.IID,
776-
&clientGitlab.UpdateMergeRequestOptions{StateEvent: clientGitlab.Ptr("close")})
777-
if err != nil {
778-
runcnx.Clients.Log.Warnf("Failed to close MR: %v", err)
779-
}
763+
// Clean up MR and namespace using TearDown
764+
tgitlab.TearDown(ctx, t, runcnx, glprovider, mr.IID, "", targetNS, originalProject.ID)
780765

781-
runcnx.Clients.Log.Infof("Deleting branch %s from fork", targetRefName)
782-
_, err = glprovider.Client().Branches.DeleteBranch(forkProject.ID, targetRefName)
766+
runcnx.Clients.Log.Infof("Deleting branch %s from fork project", targetRefName)
767+
_, err := glprovider.Client().Branches.DeleteBranch(forkProject.ID, targetRefName)
783768
if err != nil {
784-
runcnx.Clients.Log.Warnf("Failed to delete branch: %v", err)
769+
runcnx.Clients.Log.Warnf("Failed to delete branch from fork: %v", err)
785770
}
786771
}()
787772

0 commit comments

Comments
 (0)