summaryrefslogtreecommitdiffstats
path: root/integrations/integration_test.go
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2020-11-13 20:51:07 +0800
committerGitHub <noreply@github.com>2020-11-13 14:51:07 +0200
commitc296f4fed66288431fa7ec3a64f990beccd29eb1 (patch)
tree6b2f1971303967671bd5da1d1149407e410d62bd /integrations/integration_test.go
parent0ae35c66f2efe608e3176f796866c18461f0780f (diff)
downloadgitea-c296f4fed66288431fa7ec3a64f990beccd29eb1.tar.gz
gitea-c296f4fed66288431fa7ec3a64f990beccd29eb1.zip
Introduce go chi web framework as frontend of macaron, so that we can move routes from macaron to chi step by step (#7420)
* When route cannot be found on chi, go to macaron * Stick chi version to 1.5.0 * Follow router log setting
Diffstat (limited to 'integrations/integration_test.go')
-rw-r--r--integrations/integration_test.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/integrations/integration_test.go b/integrations/integration_test.go
index 13a1bac370..1e42fb5333 100644
--- a/integrations/integration_test.go
+++ b/integrations/integration_test.go
@@ -34,13 +34,13 @@ import (
"code.gitea.io/gitea/routers"
"code.gitea.io/gitea/routers/routes"
- "gitea.com/macaron/macaron"
"github.com/PuerkitoBio/goquery"
+ "github.com/go-chi/chi"
"github.com/stretchr/testify/assert"
"github.com/unknwon/com"
)
-var mac *macaron.Macaron
+var c chi.Router
type NilResponseRecorder struct {
httptest.ResponseRecorder
@@ -67,8 +67,8 @@ func TestMain(m *testing.M) {
defer cancel()
initIntegrationTest()
- mac = routes.NewMacaron()
- routes.RegisterRoutes(mac)
+ c = routes.NewChi()
+ routes.RegisterRoutes(c)
// integration test settings...
if setting.Cfg != nil {
@@ -404,7 +404,7 @@ const NoExpectedStatus = -1
func MakeRequest(t testing.TB, req *http.Request, expectedStatus int) *httptest.ResponseRecorder {
t.Helper()
recorder := httptest.NewRecorder()
- mac.ServeHTTP(recorder, req)
+ c.ServeHTTP(recorder, req)
if expectedStatus != NoExpectedStatus {
if !assert.EqualValues(t, expectedStatus, recorder.Code,
"Request: %s %s", req.Method, req.URL.String()) {
@@ -417,7 +417,7 @@ func MakeRequest(t testing.TB, req *http.Request, expectedStatus int) *httptest.
func MakeRequestNilResponseRecorder(t testing.TB, req *http.Request, expectedStatus int) *NilResponseRecorder {
t.Helper()
recorder := NewNilResponseRecorder()
- mac.ServeHTTP(recorder, req)
+ c.ServeHTTP(recorder, req)
if expectedStatus != NoExpectedStatus {
if !assert.EqualValues(t, expectedStatus, recorder.Code,
"Request: %s %s", req.Method, req.URL.String()) {
ue='backport/44533/stable29'>backport/44533/stable29 Nextcloud server, a safe home for all your data: https://github.com/nextcloud/serverwww-data
summaryrefslogtreecommitdiffstats
path: root/lib/private/memcache/memcached.php
blob: 2d3c0d16807fbe9be539abdb2353c71c27397f53 (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<?php
/**
 * @author Andreas Fischer <bantu@owncloud.com>
 * @author Bart Visscher <bartv@thisnet.nl>
 * @author Morris Jobke <hey@morrisjobke.de>
 * @author Robin Appelman <icewind@owncloud.com>
 * @author Robin McCorkell <rmccorkell@owncloud.com>
 *
 * @copyright Copyright (c) 2015, ownCloud, Inc.
 * @license AGPL-3.0
 *
 * This code is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License, version 3,
 * as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */

namespace OC\Memcache;

use OCP\IMemcache;

class Memcached extends Cache implements IMemcache {
	use CASTrait;

	/**
	 * @var \Memcached $cache
	 */
	private static $cache = null;

	use CADTrait;

	public function __construct($prefix = '') {
		parent::__construct($prefix);
		if (is_null(self::$cache)) {
			self::$cache = new \Memcached();
			$servers = \OC_Config::getValue('memcached_servers');
			if (!$servers) {
				$server = \OC_Config::getValue('memcached_server');
				if ($server) {
					$servers = array($server);
				} else {
					$servers = array(array('localhost', 11211));
				}
			}
			self::$cache->addServers($servers);
		}
	}

	/**
	 * entries in XCache gets namespaced to prevent collisions between owncloud instances and users
	 */
	protected function getNameSpace() {
		return $this->prefix;
	}

	public function get($key) {
		$result = self::$cache->get($this->getNamespace() . $key);
		if ($result === false and self::$cache->getResultCode() == \Memcached::RES_NOTFOUND) {
			return null;
		} else {
			return $result;
		}
	}

	public function set($key, $value, $ttl = 0) {
		if ($ttl > 0) {
			return self::$cache->set($this->getNamespace() . $key, $value, $ttl);
		} else {
			return self::$cache->set($this->getNamespace() . $key, $value);
		}
	}

	public function hasKey($key) {
		self::$cache->get($this->getNamespace() . $key);
		return self::$cache->getResultCode() === \Memcached::RES_SUCCESS;
	}

	public function remove($key) {
		return self::$cache->delete($this->getNamespace() . $key);
	}

	public function clear($prefix = '') {
		$prefix = $this->getNamespace() . $prefix;
		$allKeys = self::$cache->getAllKeys();
		if ($allKeys === false) {
			// newer Memcached doesn't like getAllKeys(), flush everything
			self::$cache->flush();
			return true;
		}
		$keys = array();
		$prefixLength = strlen($prefix);
		foreach ($allKeys as $key) {
			if (substr($key, 0, $prefixLength) === $prefix) {
				$keys[] = $key;
			}
		}
		if (method_exists(self::$cache, 'deleteMulti')) {
			self::$cache->deleteMulti($keys);
		} else {
			foreach ($keys as $key) {
				self::$cache->delete($key);
			}
		}
		return true;
	}

	/**
	 * Set a value in the cache if it's not already stored
	 *
	 * @param string $key
	 * @param mixed $value
	 * @param int $ttl Time To Live in seconds. Defaults to 60*60*24
	 * @return bool
	 */
	public function add($key, $value, $ttl = 0) {
		return self::$cache->add($this->getPrefix() . $key, $value, $ttl);
	}

	/**
	 * Increase a stored number
	 *
	 * @param string $key
	 * @param int $step
	 * @return int | bool
	 */
	public function inc($key, $step = 1) {
		$this->add($key, 0);
		return self::$cache->increment($this->getPrefix() . $key, $step);
	}

	/**
	 * Decrease a stored number
	 *
	 * @param string $key
	 * @param int $step
	 * @return int | bool
	 */
	public function dec($key, $step = 1) {
		return self::$cache->decrement($this->getPrefix() . $key, $step);
	}

	static public function isAvailable() {
		return extension_loaded('memcached');
	}
}