-
Notifications
You must be signed in to change notification settings - Fork 89
/
Copy pathrepository_webhook_test.go
48 lines (40 loc) · 1.41 KB
/
repository_webhook_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
//go:build e2e
// +build e2e
package test
import (
"context"
"testing"
"github.com/openshift-pipelines/pipelines-as-code/pkg/apis/pipelinesascode/v1alpha1"
ghtest "github.com/openshift-pipelines/pipelines-as-code/test/pkg/github"
"github.com/openshift-pipelines/pipelines-as-code/test/pkg/repository"
"gotest.tools/v3/assert"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)
func TestRepositoryCreation(t *testing.T) {
ctx := context.TODO()
ctx, runcnx, _, _, err := ghtest.Setup(ctx, false, false)
assert.NilError(t, err)
targetNs := "test-repo"
repo := &v1alpha1.Repository{
ObjectMeta: metav1.ObjectMeta{
Name: targetNs,
},
Spec: v1alpha1.RepositorySpec{
URL: "https://pac.test/pac/app",
},
}
defer repository.NSTearDown(ctx, t, runcnx, targetNs)
err = repository.CreateNS(ctx, targetNs, runcnx)
assert.NilError(t, err)
err = repository.CreateRepo(ctx, targetNs, runcnx, repo)
assert.NilError(t, err)
// create a new cr with same git url
targetNsNew := "test-repo-new"
repo.Name = "test-repo-new"
defer repository.NSTearDown(ctx, t, runcnx, targetNsNew)
err = repository.CreateNS(ctx, targetNsNew, runcnx)
assert.NilError(t, err)
err = repository.CreateRepo(ctx, targetNsNew, runcnx, repo)
assert.Assert(t, err != nil)
assert.Equal(t, err.Error(), "admission webhook \"validation.pipelinesascode.tekton.dev\" denied the request: repository already exists with URL: https://pac.test/pac/app")
}