-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMiscCommandTest.java
More file actions
58 lines (49 loc) · 1.57 KB
/
Copy pathMiscCommandTest.java
File metadata and controls
58 lines (49 loc) · 1.57 KB
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
package com.vaultdb;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
class MiscCommandTest {
private VaultDBEngine engine;
@BeforeEach
void setUp() {
engine = new VaultDBEngine();
}
@Test
void keysPatternMatching() {
engine.set("user:1", "a");
engine.set("user:2", "b");
engine.set("post:1", "c");
List<String> keys = engine.keys("user:*");
assertEquals(2, keys.size());
assertTrue(keys.contains("user:1"));
assertTrue(keys.contains("user:2"));
}
@Test
void typeReportsDataStructure() {
engine.set("s", "x");
engine.lpush("l", "x");
engine.hset("h", "f", "v");
engine.sadd("set", "m");
assertEquals("string", engine.type("s"));
assertEquals("list", engine.type("l"));
assertEquals("hash", engine.type("h"));
assertEquals("set", engine.type("set"));
assertEquals("none", engine.type("missing"));
}
@Test
void flushallClearsDatabase() {
engine.set("a", "1");
engine.hset("b", "f", "v");
assertEquals("OK", engine.flushall());
assertNull(engine.get("a"));
assertTrue(engine.hgetall("b").isEmpty());
}
@Test
void wrongTypeReturnsErrorViaHandler() throws IOException {
engine.lpush("listkey", "a");
String response = TestSupport.execute(engine, "GET", "listkey");
assertTrue(response.startsWith("-ERR"));
}
}