File tree Expand file tree Collapse file tree 6 files changed +147
-1
lines changed Expand file tree Collapse file tree 6 files changed +147
-1
lines changed Original file line number Diff line number Diff line change 3
3
psql --quiet -U $USER -h $HOST -p $PORT -d $DATABASE -c ' CREATE EXTENSION IF NOT EXISTS pgtap;'
4
4
5
5
pg_prove -U $USER -h $HOST -p $PORT -d $DATABASE db/tests/performance/* .test.sql
6
+
7
+ pg_prove -U $USER -h $HOST -p $PORT -d $DATABASE db/tests/unit/* .test.sql
Original file line number Diff line number Diff line change @@ -2,4 +2,4 @@ echo 'Linting migrations folder'
2
2
sqlfluff lint source/migrations/ --dialect postgres --ignore parsing --config db/linting/.sqlfluff
3
3
4
4
echo ' Linting tests folder'
5
- sqlfluff lint db/tests/performance / --dialect postgres --ignore parsing --config db/linting/.sqlfluff
5
+ sqlfluff lint db/tests/** / --dialect postgres --ignore parsing --config db/linting/.sqlfluff
Original file line number Diff line number Diff line change
1
+ BEGIN ;
2
+ -- Plan the tests.
3
+ SELECT plan(2 );
4
+
5
+ INSERT INTO rate_limit .sessions (id, name_, type_)
6
+ SELECT
7
+ ' 00000000-0000-0000-0000-000000000000' ::uuid AS id,
8
+ ' dedicated-test' ::text AS name_,
9
+ ' aggregated' ::text AS type_;
10
+
11
+ INSERT INTO rate_limit .records_aggregated (key, session_id)
12
+ SELECT
13
+ ' existing-key' AS key_,
14
+ ' 00000000-0000-0000-0000-000000000000' ::uuid AS session_id;
15
+
16
+ SELECT lives_ok(
17
+ $have$
18
+ SELECT * FROM rate_limit .agg_decrement (' existing-key' , ' 00000000-0000-0000-0000-000000000000' )
19
+ $have$,
20
+ ' rate_limit.agg_decrement does not throw an error'
21
+ );
22
+
23
+ SELECT results_eq(
24
+ $have$
25
+ SELECT count FROM rate_limit .records_aggregated
26
+ WHERE key = ' existing-key'
27
+ $have$,
28
+ $want$
29
+ SELECT 0 ::int AS count;
30
+ $want$,
31
+ ' rate_limit.agg_decrement decrements count for key'
32
+ );
33
+
34
+ -- Finish the tests and clean up.
35
+ SELECT finish FROM finish();
36
+ ROLLBACK ;
Original file line number Diff line number Diff line change
1
+ BEGIN ;
2
+ -- Plan the tests.
3
+ SELECT plan(2 );
4
+
5
+ INSERT INTO rate_limit .sessions (id, name_, type_)
6
+ SELECT
7
+ ' 00000000-0000-0000-0000-000000000000' ::uuid AS id,
8
+ ' dedicated-test' ::text AS name_,
9
+ ' aggregated' ::text AS type_;
10
+
11
+ INSERT INTO rate_limit .records_aggregated (key, session_id)
12
+ SELECT
13
+ ' existing-key' AS key_,
14
+ ' 00000000-0000-0000-0000-000000000000' ::uuid AS session_id;
15
+
16
+ SELECT results_eq(
17
+ $have$
18
+ SELECT agg_increment AS count FROM rate_limit .agg_increment (' new-key' , ' 00000000-0000-0000-0000-000000000000' )
19
+ $have$,
20
+ $want$
21
+ SELECT 1 ::int AS count;
22
+ $want$,
23
+ ' rate_limit.agg_increment returns correct count for new key'
24
+ );
25
+
26
+ SELECT results_eq(
27
+ $have$
28
+ SELECT agg_increment AS count FROM rate_limit .agg_increment (' existing-key' , ' 00000000-0000-0000-0000-000000000000' )
29
+ $have$,
30
+ $want$
31
+ SELECT 2 ::int AS count;
32
+ $want$,
33
+ ' rate_limit.agg_increment returns correct count for existing key'
34
+ );
35
+
36
+ -- Finish the tests and clean up.
37
+ SELECT finish FROM finish();
38
+ ROLLBACK ;
Original file line number Diff line number Diff line change
1
+ BEGIN ;
2
+ -- Plan the tests.
3
+ SELECT plan(2 );
4
+
5
+ INSERT INTO rate_limit .sessions (id, name_, type_)
6
+ SELECT
7
+ ' 00000000-0000-0000-0000-000000000000' ::uuid AS id,
8
+ ' dedicated-test' ::text AS name_,
9
+ ' aggregated' ::text AS type_;
10
+
11
+ INSERT INTO rate_limit .records_aggregated (key, session_id)
12
+ SELECT
13
+ ' existing-key' AS key_,
14
+ ' 00000000-0000-0000-0000-000000000000' ::uuid AS session_id;
15
+
16
+ SELECT lives_ok(
17
+ $have$
18
+ SELECT * FROM rate_limit .agg_reset_key (' existing-key' , ' 00000000-0000-0000-0000-000000000000' )
19
+ $have$,
20
+ ' rate_limit.agg_reset_key does not throw an error'
21
+ );
22
+
23
+ SELECT is_empty(
24
+ $have$
25
+ SELECT * FROM rate_limit .records_aggregated
26
+ WHERE key = ' existing-key'
27
+ $have$,
28
+ ' rate_limit.agg_reset_key decrements count for key'
29
+ );
30
+
31
+ -- Finish the tests and clean up.
32
+ SELECT finish FROM finish();
33
+ ROLLBACK ;
Original file line number Diff line number Diff line change
1
+ BEGIN ;
2
+ -- Plan the tests.
3
+ SELECT plan(2 );
4
+
5
+ INSERT INTO rate_limit .sessions (id, name_, type_)
6
+ SELECT
7
+ ' 00000000-0000-0000-0000-000000000000' ::uuid AS id,
8
+ ' dedicated-test' ::text AS name_,
9
+ ' aggregated' ::text AS type_;
10
+
11
+ INSERT INTO rate_limit .records_aggregated (key, session_id)
12
+ SELECT
13
+ ' existing-key' AS key_,
14
+ ' 00000000-0000-0000-0000-000000000000' ::uuid AS session_id
15
+ UNION
16
+ SELECT
17
+ ' another-existing-key' AS key_,
18
+ ' 00000000-0000-0000-0000-000000000000' ::uuid AS session_id;
19
+
20
+ SELECT lives_ok(
21
+ $have$
22
+ SELECT * FROM rate_limit .agg_reset_session (' 00000000-0000-0000-0000-000000000000' )
23
+ $have$,
24
+ ' rate_limit.agg_reset_session does not throw an error'
25
+ );
26
+
27
+ SELECT is_empty(
28
+ $have$
29
+ SELECT * FROM rate_limit .records_aggregated
30
+ WHERE session_id = ' 00000000-0000-0000-0000-000000000000'
31
+ $have$,
32
+ ' rate_limit.agg_reset_session removes all keys of session'
33
+ );
34
+
35
+ -- Finish the tests and clean up.
36
+ SELECT finish FROM finish();
37
+ ROLLBACK ;
You can’t perform that action at this time.
0 commit comments