Skip to content

Commit 2bd7841

Browse files
committed
Adding some more KVClient tests
1 parent a251939 commit 2bd7841

File tree

2 files changed

+52
-12
lines changed

2 files changed

+52
-12
lines changed

tests/ConsulManager.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ public static function startSingle() {
3737

3838
shell_exec(self::START_SINGLE_CMD);
3939

40-
if (file_exists(self::PID_FILE)) {
41-
echo "\nconsul pid: " . file_get_contents(self::PID_FILE) . "\n";
42-
} else {
43-
echo "\nunable to locate consul.pid file!\n";
44-
}
40+
// if (file_exists(self::PID_FILE)) {
41+
// echo "\nconsul pid: " . file_get_contents(self::PID_FILE) . "\n";
42+
// } else {
43+
// echo "\nunable to locate consul.pid file!\n";
44+
// }
4545

4646
// sleep to allow consul to setup
4747
sleep(5);

tests/Usage/KV/KVClientUsageTest.php

Lines changed: 47 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,16 @@
2929
*/
3030
class KVClientUsageTest extends \PHPUnit_Framework_TestCase {
3131

32-
const KVKey = 'testkey';
33-
const KVValue = 'testvalue';
32+
const KVKey1 = 'testkey1';
33+
const KVValue1 = 'testvalue1';
34+
35+
const KVKey2 = 'testkey2';
36+
const KVValue2 = 'testvalue2';
37+
38+
const KVKey3 = 'testkey3';
39+
const KVValue3 = 'testvalue3';
40+
41+
const KVPrefix = 'tests';
3442

3543
/**
3644
* Sets up the fixture, for example, open a network connection.
@@ -63,7 +71,7 @@ public function testCanConstructClient() {
6371
public function testCanPutKey() {
6472
$client = new KVClient(new Config());
6573

66-
list($wm, $err) = $client->put(new KVPair(['Key' => self::KVKey, 'Value' => self::KVValue]));
74+
list($wm, $err) = $client->put(new KVPair(['Key' => self::KVKey1, 'Value' => self::KVValue1]));
6775
$this->assertNull($err, sprintf('Unable to set kvp: %s', (string)$err));
6876
$this->assertInstanceOf(WriteMeta::class, $wm);
6977
}
@@ -73,9 +81,9 @@ public function testCanPutKey() {
7381
*/
7482
public function testCanGetKey() {
7583
$client = new KVClient(new Config());
76-
$client->put(new KVPair(['Key' => self::KVKey, 'Value' => self::KVValue]));
84+
$client->put(new KVPair(['Key' => self::KVKey1, 'Value' => self::KVValue1]));
7785

78-
list($kv, $qm, $err) = $client->get(self::KVKey);
86+
list($kv, $qm, $err) = $client->get(self::KVKey1);
7987
$this->assertNull($err, sprintf('KV::get returned error: %s', (string)$err));
8088
$this->assertInstanceOf(QueryMeta::class, $qm);
8189
$this->assertInstanceOf(KVPair::class, $kv);
@@ -86,9 +94,9 @@ public function testCanGetKey() {
8694
*/
8795
public function testCanDeleteKey() {
8896
$client = new KVClient(new Config());
89-
$client->put(new KVPair(['Key' => self::KVKey, 'Value' => self::KVValue]));
97+
$client->put(new KVPair(['Key' => self::KVKey1, 'Value' => self::KVValue1]));
9098

91-
list($wm, $err) = $client->delete(self::KVKey);
99+
list($wm, $err) = $client->delete(self::KVKey1);
92100
$this->assertNull($err, sprintf('KV::delete returned error: %s', $err));
93101
$this->assertInstanceOf(
94102
WriteMeta::class,
@@ -99,4 +107,36 @@ public function testCanDeleteKey() {
99107
is_object($wm) ? get_class($wm) : gettype($wm)
100108
));
101109
}
110+
111+
/**
112+
* @depends testCanPutKey
113+
*/
114+
public function testCanGetNoPrefixList() {
115+
$client = new KVClient(new Config());
116+
$client->put(new KVPair(['Key' => self::KVKey1, 'Value' => self::KVValue1]));
117+
$client->put(new KVPair(['Key' => self::KVKey2, 'Value' => self::KVValue2]));
118+
$client->put(new KVPair(['Key' => self::KVKey3, 'Value' => self::KVValue3]));
119+
120+
list($list, $qm, $err) = $client->valueList();
121+
$this->assertNull($err, sprintf('KV::valueList returned error: %s', $err));
122+
$this->assertInstanceOf(QueryMeta::class, $qm);
123+
$this->assertInternalType('array', $list);
124+
$this->assertCount(3, $list);
125+
}
126+
127+
/**
128+
* @depends testCanPutKey
129+
*/
130+
public function testCanGetPrefixList() {
131+
$client = new KVClient(new Config());
132+
$client->put(new KVPair(['Key' => self::KVPrefix . '/' . self::KVKey1, 'Value' => self::KVValue1]));
133+
$client->put(new KVPair(['Key' => self::KVPrefix . '/' . self::KVKey2, 'Value' => self::KVValue2]));
134+
$client->put(new KVPair(['Key' => self::KVPrefix . '/' . self::KVKey3, 'Value' => self::KVValue3]));
135+
136+
list($list, $qm, $err) = $client->valueList(self::KVPrefix);
137+
$this->assertNull($err, sprintf('KV::valueList returned error: %s', $err));
138+
$this->assertInstanceOf(QueryMeta::class, $qm);
139+
$this->assertInternalType('array', $list);
140+
$this->assertCount(3, $list);
141+
}
102142
}

0 commit comments

Comments
 (0)