From a1f5364d7f43d708d326e7dcdb409ab157ce9dfe Mon Sep 17 00:00:00 2001
From: Lukas Reschke <lukas@statuscode.ch>
Date: Thu, 29 Sep 2016 00:53:53 +0200
Subject: [PATCH] Generate coverage for quick DB tests

This adds the "QUICKDB" group which excludes some tests that abuse unit tests as integration tests as displayed in https://github.com/nextcloud/server/issues/1626

Signed-off-by: Lukas Reschke <lukas@statuscode.ch>
---
 .drone.yml                                     | 18 ++++++++++++++----
 .../tests/EtagPropagationTest.php              |  2 +-
 .../tests/GroupEtagPropagationTest.php         |  2 +-
 apps/files_sharing/tests/SharedMountTest.php   |  2 +-
 autotest.sh                                    |  7 +++++--
 tests/lib/TestCase.php                         |  6 ++++--
 6 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/.drone.yml b/.drone.yml
index a3c3870dcdd..92dde90bf6d 100644
--- a/.drone.yml
+++ b/.drone.yml
@@ -301,7 +301,7 @@ pipeline:
     when:
       matrix:
         TESTS: integration-sharees-features
-  codecov:
+  nodb-codecov:
     image: nextcloudci/php7.0:php7.0-2
     commands:
       - TEST_SELECTION=NODB ./autotest.sh sqlite
@@ -310,12 +310,22 @@ pipeline:
       - sh -c "if [ '$DRONE_BUILD_EVENT' != 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -t 117641e2-a9e8-4b7b-984b-ae872d9b05f5 -f tests/autotest-clover-sqlite.xml; fi"
     when:
       matrix:
-        TESTS: codecov
-
+        TESTS: nodb-codecov
+  db-codecov:
+    image: nextcloudci/php7.0:php7.0-2
+    commands:
+      - TEST_SELECTION=QUICKDB ./autotest.sh sqlite
+      - wget https://codecov.io/bash -O codecov.sh
+      - sh -c "if [ '$DRONE_BUILD_EVENT' = 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -P $DRONE_PULL_REQUEST -t 117641e2-a9e8-4b7b-984b-ae872d9b05f5 -f tests/autotest-clover-sqlite.xml; fi"
+      - sh -c "if [ '$DRONE_BUILD_EVENT' != 'pull_request' ]; then bash codecov.sh -B $DRONE_BRANCH -C $DRONE_COMMIT -t 117641e2-a9e8-4b7b-984b-ae872d9b05f5 -f tests/autotest-clover-sqlite.xml; fi"
+    when:
+      matrix:
+        TESTS: db-codecov
 matrix:
   include:
     - TESTS: signed-off-check
-    - TESTS: codecov
+    - TESTS: nodb-codecov
+    - TESTS: db-codecov    
     - TESTS: integration-capabilities_features
     - TESTS: integration-federation_features
     - TESTS: integration-auth
diff --git a/apps/files_sharing/tests/EtagPropagationTest.php b/apps/files_sharing/tests/EtagPropagationTest.php
index 977f98f0497..4aba9e29113 100644
--- a/apps/files_sharing/tests/EtagPropagationTest.php
+++ b/apps/files_sharing/tests/EtagPropagationTest.php
@@ -34,7 +34,7 @@ use OC\Files\View;
 /**
  * Class EtagPropagationTest
  *
- * @group DB
+ * @group SLOWDB
  *
  * @package OCA\Files_Sharing\Tests
  */
diff --git a/apps/files_sharing/tests/GroupEtagPropagationTest.php b/apps/files_sharing/tests/GroupEtagPropagationTest.php
index 0ff3a4c01c6..eeb3c06bc59 100644
--- a/apps/files_sharing/tests/GroupEtagPropagationTest.php
+++ b/apps/files_sharing/tests/GroupEtagPropagationTest.php
@@ -28,7 +28,7 @@ use OC\Files\Filesystem;
 use OC\Files\View;
 
 /**
- * @group DB
+ * @group SLOWDB
  *
  * @package OCA\Files_Sharing\Tests
  */
diff --git a/apps/files_sharing/tests/SharedMountTest.php b/apps/files_sharing/tests/SharedMountTest.php
index 7427304eb14..5f769852dc8 100644
--- a/apps/files_sharing/tests/SharedMountTest.php
+++ b/apps/files_sharing/tests/SharedMountTest.php
@@ -31,7 +31,7 @@ namespace OCA\Files_Sharing\Tests;
 /**
  * Class SharedMountTest
  *
- * @group DB
+ * @group SLOWDB
  */
 class SharedMountTest extends TestCase {
 
diff --git a/autotest.sh b/autotest.sh
index 2dfa961a1a2..eca3d81c048 100755
--- a/autotest.sh
+++ b/autotest.sh
@@ -293,11 +293,14 @@ function execute_tests {
 		export XDEBUG_CONFIG=$_XDEBUG_CONFIG
 	fi
 	GROUP=''
+	if [ "$TEST_SELECTION" == "QUICKDB" ]; then
+		GROUP='--group DB --exclude-group=SLOWDB'
+	fi
 	if [ "$TEST_SELECTION" == "DB" ]; then
-		GROUP='--group DB'
+		GROUP='--group DB,SLOWDB'
 	fi
 	if [ "$TEST_SELECTION" == "NODB" ]; then
-		GROUP='--exclude-group DB'
+		GROUP='--exclude-group DB,SLOWDB'
 	fi
 
 	COVER=''
diff --git a/tests/lib/TestCase.php b/tests/lib/TestCase.php
index 0389ef5d46b..7ccff382357 100644
--- a/tests/lib/TestCase.php
+++ b/tests/lib/TestCase.php
@@ -435,8 +435,10 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase {
 			return true;
 		}
 		$annotations = $this->getAnnotations();
-		if (isset($annotations['class']['group']) && in_array('DB', $annotations['class']['group'])) {
-			return true;
+		if (isset($annotations['class']['group'])) {
+			if(in_array('DB', $annotations['class']['group']) || in_array('SLOWDB', $annotations['class']['group']) ) {
+				return true;
+			}
 		}
 
 		return false;
-- 
GitLab