-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Tests failed because sometimes a tag appears in tag stats as `Foo` and other times as `foo`. So teach the tag stats to always lowercase tag names for consistent formatting, both in tests and as things change in time. Replace the PL/Perl-based mocks, which used the `%_SHARED` hash, with a session-based config value. Required because security appears to have been increased on `%_SHARED`, as it was empty inside the `SECURITY DEFINER` functions that called mock functions that use it. Since we require Postgres 12 or higher now, we can do away with that hack ans use the much cleaner configuration-based mocks. Update the CI workflow to test on Postgres 16 and use the most recent checkout action. While at it, eliminate stray diagnostic lines from test output from the pgTAP tests by using a different unprintable character in the `distributions.pg` test, and using error descriptions instead of the invalid terms and tags in `types.pg`.
- Loading branch information
Showing
9 changed files
with
107 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
-- sql/19-tag-stats-json.sql SQL Migration | ||
|
||
SET client_min_messages TO warning; | ||
|
||
BEGIN; | ||
|
||
CREATE OR REPLACE FUNCTION tag_stats_json( | ||
num_popular INT DEFAULT 56 | ||
) RETURNS TEXT LANGUAGE sql STABLE STRICT AS $$ | ||
/* | ||
% select tag_stats_json(4); | ||
tag_stats_json | ||
────────────────────────────────────────────── | ||
{ ↵ | ||
"count": 212, ↵ | ||
"popular": [ ↵ | ||
{"tag": "data types", "dists": 4}, ↵ | ||
{"tag": "key value", "dists": 2}, ↵ | ||
{"tag": "france", "dists": 1}, ↵ | ||
{"tag": "key value pair", "dists": 1} ↵ | ||
] ↵ | ||
} ↵ | ||
Returns a JSON representation of tag statistics. These include: | ||
* `count`: A count of all tags in the database. | ||
* `popular`: A list of the most used tags in the system, listed in descending | ||
order by the number of uses. | ||
Since tags are case-insensitive, `tag_stats_json()` returns lowercases tag | ||
names. | ||
Pass in the optional `num_popular` parameter to limit the number of tags that | ||
appear in the popular list. The default limit is 56. | ||
*/ | ||
SELECT E'{\n "count": ' || COUNT(DISTINCT tag) || E',\n "popular": [\n' | ||
|| array_to_string(ARRAY( | ||
SELECT ' {"tag": ' || json_value(LOWER(tag)) | ||
|| ', "dists": ' || COUNT(DISTINCT distribution) || E'}' | ||
FROM distribution_tags | ||
GROUP BY tag | ||
ORDER BY COUNT(DISTINCT distribution) DESC, tag | ||
LIMIT $1 | ||
), E',\n') || E'\n ]\n}\n' | ||
FROM distribution_tags | ||
$$; | ||
|
||
COMMIT; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -70,18 +70,12 @@ SELECT is( | |
/****************************************************************************/ | ||
-- Now mock rand_str_of_len() | ||
CREATE SCHEMA mock; | ||
|
||
CREATE FUNCTION mock.set_rand_str( | ||
string TEXT | ||
) RETURNS SETOF BOOLEAN LANGUAGE plperl AS $$ | ||
$_SHARED{random_string} = shift; | ||
return; | ||
$$; | ||
SET SESSION mock.random_string = 'foobar'; | ||
|
||
CREATE FUNCTION mock.rand_str_of_len( | ||
INTEGER | ||
) RETURNS TEXT LANGUAGE plperl AS $$ | ||
return $_SHARED{random_string}; | ||
) RETURNS TEXT LANGUAGE sql AS $$ | ||
SELECT current_setting('mock.random_string') | ||
$$; | ||
|
||
DO LANGUAGE plpgsql $$ | ||
|
@@ -90,7 +84,6 @@ BEGIN | |
END; | ||
$$; | ||
|
||
SELECT * FROM set_rand_str('foobar'); | ||
SELECT is(rand_str_of_len(NULL), 'foobar', 'Should get mocked random string'); | ||
|
||
/****************************************************************************/ | ||
|
@@ -174,7 +167,7 @@ SELECT ok( | |
); | ||
UPDATE users SET status = 'active' WHERE nickname = 'strongrrl'; | ||
|
||
SELECT * FROM set_rand_str('howdy'); | ||
SET SESSION mock.random_string = 'howdy'; | ||
SELECT is( | ||
forgot_password('strongrrl'), | ||
ARRAY['howdy', '[email protected]'], | ||
|
@@ -190,7 +183,7 @@ SELECT is( | |
) FROM tokens WHERE token = 'howdy'; | ||
|
||
-- Create another token for the same user. | ||
SELECT * FROM set_rand_str('booyah'); | ||
SET SESSION mock.random_string = 'booyah'; | ||
SELECT is( | ||
forgot_password('theory'), | ||
ARRAY['booyah','[email protected]'], | ||
|
@@ -276,7 +269,7 @@ SELECT is(set_by, 'kamala', 'New user should have been set by self') | |
FROM users WHERE nickname = 'kamala'; | ||
|
||
-- Update the mocked random string. | ||
SELECT * FROM set_rand_str('clanker'); | ||
SET SESSION mock.random_string = 'clanker'; | ||
SELECT is(rand_str_of_len(NULL), 'clanker', 'Should get new mocked random string'); | ||
|
||
-- Now clear the password. | ||
|
@@ -311,7 +304,7 @@ SELECT throws_like( | |
); | ||
|
||
-- Create another token for the same user. | ||
SELECT * FROM set_rand_str('mobius'); | ||
SET SESSION mock.random_string = 'mobius'; | ||
SELECT is( | ||
clear_password('theory', 'kamala', '10 days'), | ||
ARRAY['mobius','[email protected]'], | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters