Load in-repo configuration

Change-Id: I225934407ce31f92a9b6df4bc282fbd5ec2968b3
diff --git a/tests/base.py b/tests/base.py
index 5e1befe..497d706 100755
--- a/tests/base.py
+++ b/tests/base.py
@@ -1307,7 +1307,7 @@
                 # processed
                 self.eventQueuesJoin()
                 self.sched.run_handler_lock.acquire()
-                if (not self.merge_client.build_sets and
+                if (not self.merge_client.jobs and
                     all(self.eventQueuesEmpty()) and
                     self.haveAllBuildsReported() and
                     self.areAllBuildsWaiting()):
@@ -1376,3 +1376,19 @@
         """ % os.path.abspath(path))
         f.close()
         self.config.set('zuul', 'tenant_config', f.name)
+
+    def addCommitToRepo(self, project, message, files, branch='master'):
+        path = os.path.join(self.upstream_root, project)
+        repo = git.Repo(path)
+        repo.head.reference = branch
+        zuul.merger.merger.reset_repo_to_head(repo)
+        for fn, content in files.items():
+            fn = os.path.join(path, fn)
+            with open(fn, 'w') as f:
+                f.write(content)
+            repo.index.add([fn])
+        commit = repo.index.commit(message)
+        repo.heads[branch].commit = commit
+        repo.head.reference = branch
+        repo.git.clean('-x', '-f', '-d')
+        repo.heads[branch].checkout()
diff --git a/tests/fixtures/config/in-repo/common.yaml b/tests/fixtures/config/in-repo/common.yaml
new file mode 100644
index 0000000..96aebd6
--- /dev/null
+++ b/tests/fixtures/config/in-repo/common.yaml
@@ -0,0 +1,36 @@
+pipelines:
+  - name: check
+    manager: IndependentPipelineManager
+    source:
+      gerrit
+    trigger:
+      gerrit:
+        - event: patchset-created
+    success:
+      gerrit:
+        verified: 1
+    failure:
+      gerrit:
+        verified: -1
+
+  - name: tenant-one-gate
+    manager: DependentPipelineManager
+    success-message: Build succeeded (tenant-one-gate).
+    source:
+      gerrit
+    trigger:
+      gerrit:
+        - event: comment-added
+          approval:
+            - approved: 1
+    success:
+      gerrit:
+        verified: 2
+        submit: true
+    failure:
+      gerrit:
+        verified: -2
+    start:
+      gerrit:
+        verified: 0
+    precedence: high
diff --git a/tests/fixtures/config/in-repo/main.yaml b/tests/fixtures/config/in-repo/main.yaml
new file mode 100644
index 0000000..df7dadd
--- /dev/null
+++ b/tests/fixtures/config/in-repo/main.yaml
@@ -0,0 +1,8 @@
+tenants:
+  - name: tenant-one
+    include:
+      - common.yaml
+    source:
+      gerrit:
+        repos:
+          - org/project
diff --git a/tests/fixtures/config/in-repo/zuul.conf b/tests/fixtures/config/in-repo/zuul.conf
new file mode 100644
index 0000000..14708aa
--- /dev/null
+++ b/tests/fixtures/config/in-repo/zuul.conf
@@ -0,0 +1,36 @@
+[gearman]
+server=127.0.0.1
+
+[zuul]
+tenant_config=tests/fixtures/config/in-repo/main.yaml
+url_pattern=http://logs.example.com/{change.number}/{change.patchset}/{pipeline.name}/{job.name}/{build.number}
+job_name_in_report=true
+
+[merger]
+git_dir=/tmp/zuul-test/git
+git_user_email=zuul@example.com
+git_user_name=zuul
+zuul_url=http://zuul.example.com/p
+
+[swift]
+authurl=https://identity.api.example.org/v2.0/
+user=username
+key=password
+tenant_name=" "
+
+default_container=logs
+region_name=EXP
+logserver_prefix=http://logs.example.org/server.app/
+
+[connection gerrit]
+driver=gerrit
+server=review.example.com
+user=jenkins
+sshkey=none
+
+[connection smtp]
+driver=smtp
+server=localhost
+port=25
+default_from=zuul@example.com
+default_to=you@example.com
diff --git a/tests/test_v3.py b/tests/test_v3.py
index 2e16742..69e66a0 100644
--- a/tests/test_v3.py
+++ b/tests/test_v3.py
@@ -15,6 +15,7 @@
 # under the License.
 
 import logging
+import textwrap
 
 from tests.base import (
     ZuulTestCase,
@@ -62,3 +63,30 @@
 
         self.assertEqual(A.reported, 2, "Activity in tenant two should"
                          "not affect tenant one")
+
+    def test_in_repo_config(self):
+        in_repo_conf = textwrap.dedent(
+            """
+            projects:
+              - name: org/project
+                tenant-one-gate:
+                  - project-test1
+            """)
+
+        self.addCommitToRepo('org/project', 'add zuul conf',
+                             {'.zuul.yaml': in_repo_conf})
+
+        self.setup_config('config/in-repo/zuul.conf')
+        self.sched.reconfigure(self.config)
+
+        A = self.fake_gerrit.addFakeChange('org/project', 'master', 'A')
+        A.addApproval('CRVW', 2)
+        self.fake_gerrit.addEvent(A.addApproval('APRV', 1))
+        self.waitUntilSettled()
+        self.assertEqual(self.getJobFromHistory('project-test1').result,
+                         'SUCCESS')
+        self.assertEqual(A.data['status'], 'MERGED')
+        self.assertEqual(A.reported, 2,
+                         "A should report start and success")
+        self.assertIn('tenant-one-gate', A.messages[1],
+                      "A should transit tenant-one gate")