-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add e2e test for pending prs processed
Add a new test that will test that when the watcher is down and a PR is created, the PipelineRuns are kept in Pending state. When the watcher is up again, the PipelineRuns are restarted. Some refactoring has been done to move some functions to their own. Signed-off-by: Chmouel Boudjnah <chmouel@redhat.com>
- Loading branch information
Showing
3 changed files
with
180 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package kubestuff | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
"time" | ||
|
||
"github.com/openshift-pipelines/pipelines-as-code/pkg/params" | ||
"gotest.tools/v3/assert" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func ScaleDeployment(ctx context.Context, t *testing.T, runcnx *params.Run, replicas int32, deploymentName, namespace string) { | ||
scale, err := runcnx.Clients.Kube.AppsV1().Deployments(namespace).GetScale(ctx, deploymentName, metav1.GetOptions{}) | ||
assert.NilError(t, err) | ||
scale.Spec.Replicas = replicas | ||
time.Sleep(5 * time.Second) | ||
_, err = runcnx.Clients.Kube.AppsV1().Deployments(namespace).UpdateScale(ctx, deploymentName, scale, metav1.UpdateOptions{}) | ||
assert.NilError(t, err) | ||
runcnx.Clients.Log.Infof("Deployment %s in namespace %s scaled to %d replicas", deploymentName, namespace, replicas) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package repository | ||
|
||
import ( | ||
"context" | ||
"os" | ||
|
||
"github.com/google/go-github/v62/github" | ||
"github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode/v1alpha1" | ||
"github.com/openshift-pipelines/pipelines-as-code/pkg/params" | ||
"github.com/openshift-pipelines/pipelines-as-code/pkg/params/info" | ||
"github.com/openshift-pipelines/pipelines-as-code/test/pkg/cctx" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func CreateGlobalRepo(ctx context.Context) (context.Context, string, *params.Run, error) { | ||
runcnx := params.New() | ||
if err := runcnx.Clients.NewClients(ctx, &runcnx.Info); err != nil { | ||
return ctx, "", nil, err | ||
} | ||
|
||
ctx, err := cctx.GetControllerCtxInfo(ctx, runcnx) | ||
if err != nil { | ||
return ctx, "", nil, err | ||
} | ||
|
||
globalNS := info.GetNS(ctx) | ||
|
||
repo := &v1alpha1.Repository{ | ||
ObjectMeta: metav1.ObjectMeta{ | ||
Name: info.DefaultGlobalRepoName, | ||
}, | ||
Spec: v1alpha1.RepositorySpec{ | ||
ConcurrencyLimit: github.Int(2), | ||
}, | ||
} | ||
|
||
if err := CreateRepo(ctx, globalNS, runcnx, repo); err != nil { | ||
return ctx, "", nil, err | ||
} | ||
|
||
return ctx, globalNS, runcnx, nil | ||
} | ||
|
||
func CleanUpGlobalRepo(runcnx *params.Run, globalNS string) error { | ||
if os.Getenv("TEST_NOCLEANUP") != "true" { | ||
runcnx.Clients.Log.Infof("Cleaning up global repo %s in %s", info.DefaultGlobalRepoName, globalNS) | ||
return runcnx.Clients.PipelineAsCode.PipelinesascodeV1alpha1().Repositories(globalNS).Delete( | ||
context.Background(), info.DefaultGlobalRepoName, metav1.DeleteOptions{}) | ||
} | ||
return nil | ||
} |