theory / pgtap

PostgreSQL Unit Testing Suite
https://pgtap.org
984 stars 92 forks source link

add has_comment() #322

Open kbrannen opened 1 year ago

kbrannen commented 1 year ago

This is probably incredibly low on the priority list, but it just occurred to me that there is no has_comment() function. I don't think we need hasnt_comment(), but it could be done if it was simple as doing "select not has_comment(...)".

There are 2 paths to take on this if done:

  1. has_comment(name, type [,comment] [,description]) -- where type is database, schema, function, table, ...
  2. has_db_comment(), has_schema_comment(), has_function_comment(), ...

It gets a little crazy because just about every type of object can have a comment. I think I'd rather do 1 to avoid a proliferation of functions.

I'm not sure if we want to check if the object simply has a comment which would be "has_comment()", or if we'd care about know that the comment value is what we expect which I think would work better with "comment_is()". Or do we need both? :)

You can see the comments by adding "+" to almost any command in psql, e.g. \l+, \dt+, \d+, \dn+, etc. The comment will show in the "Description" column. The value gets there with the command COMMENT ON {object} {name} IS '{description}'; hence has_comment() but I suppose we could call it has_description().

rodo commented 3 weeks ago

@theory what are your thoughts on this on the function naming ?

If the following seems ok for you ?

SELECT table_comment_is ( :schema, :table, :comment, :description );
SELECT table_comment_is ( :schema, :table, :comment );
SELECT table_comment_is ( :table, :comment, :description );
SELECT table_comment_is ( :table, :comment );
SELECT column_comment_is ( :schema, :table, :column, :comment, :description );
SELECT column_comment_is ( :schema, :table, :column, :comment );
SELECT column_comment_is ( :table, :column, :comment, :description );
SELECT column_comment_is ( :table, :column, :comment );

And so on for other objects ?

theory commented 3 weeks ago

Yeah, that looks like other stuff we have now.

rodo commented 3 weeks ago

Done in https://github.com/theory/pgtap/pull/306