@@ -46,11 +46,12 @@ var (
4646 k8s * kubernetes.Clientset
4747 crdK8s crdclient.Client
4848 tests = map [string ]Test {
49- "git-operator-is-running" : TestGitOperatorIsRunning ,
50- "github-branch-sync" : TestGithubBranchSync ,
51- "github-pr-github-sync" : TestGithubPRSync ,
52- "github-pr-crd-sync" : TestGithubPRCRDSync ,
53- "github-gitops-api" : TestGitopsAPI ,
49+ "git-operator-is-running" : TestGitOperatorIsRunning ,
50+ "github-branch-sync" : TestGithubBranchSync ,
51+ "github-pr-github-sync" : TestGithubPRSync ,
52+ "github-pr-crd-sync" : TestGithubPRCRDSync ,
53+ "github-gitops-api" : TestGitopsAPI ,
54+ "github-gitops-api-search-path" : TestGitopsAPISearchPath ,
5455 }
5556 scheme = runtime .NewScheme ()
5657 log = ctrl .Log .WithName ("e2e" )
@@ -85,7 +86,7 @@ func main() {
8586 os .Exit (1 )
8687 }
8788
88- timeout = flag .Duration ("timeout" , 10 * time .Minute , "Global timeout for all tests" )
89+ timeout = flag .Duration ("timeout" , 15 * time .Minute , "Global timeout for all tests" )
8990 flag .Parse ()
9091
9192 utilruntime .Must (clientgoscheme .AddToScheme (scheme ))
@@ -181,6 +182,50 @@ func TestGitopsAPI(ctx context.Context, test *console.TestResults) error {
181182 return err
182183}
183184
185+ func TestGitopsAPISearchPath (ctx context.Context , test * console.TestResults ) error {
186+ git , err := connectors .NewConnector (ctx , crdK8s , k8s , log , "platform-system" , "https://github.com/" + repository , & v1.LocalObjectReference {
187+ Name : "github" ,
188+ })
189+ if err != nil {
190+ return err
191+ }
192+ branchName := getBranchName ("test" )
193+ body := `
194+ {
195+ "apiVersion": "v1",
196+ "data": {
197+ "some-key": "some-value",
198+ "new-key": "new-value"
199+ },
200+ "kind": "ConfigMap",
201+ "metadata": {
202+ "name": "test-configmap",
203+ "namespace": "default"
204+ }
205+ }
206+ `
207+
208+ log .Info ("json" , "value" , body )
209+ _ , pr , err := controllers .HandleGitopsAPI (ctx , log , git , gitv1.GitopsAPI {
210+ Spec : gitv1.GitopsAPISpec {
211+ GitRepository : repository ,
212+ Branch : branchName ,
213+ SearchPath : "resources/" ,
214+ PullRequest : & gitv1.PullRequestTemplate {
215+ Title : "New Automated PR - {{.metadata.name}}" ,
216+ Body : "Somebody created a new PR {{.metadata.name}}" ,
217+ },
218+ },
219+ }, bytes .NewReader ([]byte (body )))
220+
221+ if pr != 0 {
222+ if err := git .ClosePullRequest (ctx , pr ); err != nil {
223+ return err
224+ }
225+ }
226+ return err
227+ }
228+
184229func TestGitOperatorIsRunning (ctx context.Context , test * console.TestResults ) error {
185230 pods , err := k8s .CoreV1 ().Pods (namespace ).List (ctx , metav1.ListOptions {LabelSelector : "control-plane=git-operator" })
186231 if err != nil {
@@ -206,7 +251,7 @@ func TestGithubBranchSync(ctx context.Context, test *console.TestResults) error
206251 }
207252 test .Passf ("TestGithubBranchSync" , "Successfully created branch %s" , branchName )
208253
209- gitBranchGetCtx , cancelFunc := context .WithTimeout (ctx , 2 * time .Minute )
254+ gitBranchGetCtx , cancelFunc := context .WithTimeout (ctx , 3 * time .Minute )
210255 defer cancelFunc ()
211256 crdName := fmt .Sprintf ("gitrepository-sample-%s" , branchName )
212257 gitBranch , err := waitForGitBranch (gitBranchGetCtx , crdName )
@@ -268,7 +313,7 @@ func TestGithubPRSync(ctx context.Context, test *console.TestResults) error {
268313 return err
269314 }
270315
271- gitPRGetCtx , cancelFunc := context .WithTimeout (ctx , 2 * time .Minute )
316+ gitPRGetCtx , cancelFunc := context .WithTimeout (ctx , 3 * time .Minute )
272317 defer cancelFunc ()
273318 crdName := fmt .Sprintf ("gitrepository-sample-%d" , * pr .Number )
274319 gitPR , err := waitForGitPullRequest (gitPRGetCtx , crdName )
@@ -363,7 +408,7 @@ func TestGithubPRCRDSync(ctx context.Context, test *console.TestResults) error {
363408 return err
364409 }
365410
366- gitPRGetCtx , cancelFunc := context .WithTimeout (ctx , 2 * time .Minute )
411+ gitPRGetCtx , cancelFunc := context .WithTimeout (ctx , 3 * time .Minute )
367412 defer cancelFunc ()
368413 gitPR , err := waitForGitPullRequestFromCrd (gitPRGetCtx , branchName )
369414 if err != nil {
0 commit comments