-
Notifications
You must be signed in to change notification settings - Fork 0
/
scyther_test.ts
164 lines (116 loc) · 3.92 KB
/
scyther_test.ts
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
154
155
156
157
158
159
160
161
162
163
164
import { assert, assertEquals, assertNotEquals, v4 } from "./deps.ts";
import { Queue } from "./scyther.ts";
import { SCYTHER_HOST } from "./env.ts";
const name: string = "foobar";
async function delete_queue(id: string): Promise<void> {
await fetch(`${SCYTHER_HOST}/queues/${id}`, { method: "DELETE" });
}
Deno.test("imports", async () => {
assertNotEquals(Queue, undefined);
});
Deno.test("url", async () => {
const url: string = (new Queue(name)).url;
assertEquals(url, `${SCYTHER_HOST}/queues/${name}`);
});
Deno.test("new", async () => {
const queue: Queue = await Queue.new();
assertNotEquals(queue.url, null);
assertNotEquals(queue.url, undefined);
assertEquals(await queue.name, null);
await delete_queue(await queue.id);
});
Deno.test("attaches", async () => {
const name: string = v4.generate();
await Queue.new({ name });
const queue: Queue = new Queue(name);
assertEquals(await queue.name, name);
await delete_queue(name);
});
Deno.test("id", async () => {
const queue: Queue = await Queue.new();
const id: string = await queue.id;
assert(v4.validate(id));
await delete_queue(id);
});
Deno.test("name", async () => {
const name: string = v4.generate();
const queue: Queue = await Queue.new({ name });
assertEquals(await queue.name, name);
await delete_queue(name);
});
Deno.test("ephemeral", async () => {
const queue: Queue = await Queue.new();
assertEquals(await queue.ephemeral, false);
await delete_queue(await queue.id);
});
Deno.test("capacity", async () => {
const capacity: number = 100;
const queue: Queue = await Queue.new();
const queue_cap: Queue = await Queue.new({ capacity });
assertEquals(await queue.capacity, null);
assertEquals(await queue_cap.capacity, capacity);
await delete_queue(await queue.id);
await delete_queue(await queue_cap.id);
});
Deno.test("size", async () => {
const queue: Queue = await Queue.new();
assertEquals(await queue.size, 0);
await queue.push("foobar");
assertEquals(await queue.size, 1);
await delete_queue(await queue.id);
});
Deno.test("head", async () => {
const queue: Queue = await Queue.new();
const message: string = v4.generate();
await queue.push(message);
await queue.push(v4.generate());
assertEquals(await queue.head, message);
assertNotEquals(await queue.head, message);
await delete_queue(await queue.id);
});
Deno.test("head no_message", async () => {
const queue: Queue = await Queue.new();
await queue.head;
assertEquals(await queue.head, null);
await delete_queue(await queue.id);
});
Deno.test("tail", async () => {
const queue: Queue = await Queue.new();
const message: string = v4.generate();
await queue.push(v4.generate());
await queue.push(message);
assertEquals(await queue.tail, message);
assertNotEquals(await queue.tail, message);
await delete_queue(await queue.id);
});
Deno.test("tail no_message", async () => {
const queue: Queue = await Queue.new();
assertEquals(await queue.tail, null);
await delete_queue(await queue.id);
});
Deno.test("consume", async () => {
const queue: Queue = await Queue.new();
const message: string = v4.generate();
await queue.push(v4.generate());
await queue.push(message);
await queue.push(v4.generate());
assertEquals(await queue.consume(1), message);
assertNotEquals(await queue.consume(1), message);
await delete_queue(await queue.id);
});
Deno.test("consume no_message", async () => {
const queue: Queue = await Queue.new();
assertEquals(await queue.consume(1), null);
await delete_queue(await queue.id);
});
Deno.test("peek", async () => {
const queue: Queue = await Queue.new();
const message: string = v4.generate();
await queue.push(v4.generate());
await queue.push(message);
await queue.push(v4.generate());
assertEquals(await queue.peek(1), message);
assertEquals(await queue.peek(1), message);
assertNotEquals(await queue.peek(0), message);
await delete_queue(await queue.id);
});