Skip to content

Add has_view(:schema, :name) and hasnt_view(:schema, :name) #230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Jan 17, 2020

Conversation

Godwottery
Copy link
Contributor

This is PoC for #219

I haven't been able to test it due to lack of suitable machine.

Add support for has_view(schema, name)
Add support for hasnt_view( :schema, :name)
Fix comment
Fix missing documentation.
Add tests for has_view and hasnt_view.
Update test count
Update expected results
De-duplicate added code. Call the (:schema,:name,:description) versions with default description.
Update test count
Try to fix tests
@Godwottery
Copy link
Contributor Author

I got stuck on the unit-tests. I can not seem to get them to line up.
Could someone please point me in the direction where I can find the cause.

test/sql/hastap.sql .. 1/896 
# Failed test 115: "has_view(sch, view) should pass"
#         have: false
#         want: true
# Failed test 116: "has_view(sch, view) should have the proper description"
#         have: tables
#         want: View "information_schema.tables" should exist
# Failed test 119: "has_view(sch, non-existent view, desc) should have the proper description"
#         have: __SDFSDFD__
#         want: View "foo.__SDFSDFD__" should not exist
# Failed test 136: "hasnt_view(sch, view) should fail"
#         have: true
#         want: false
# Failed test 137: "hasnt_view(sch, view) should have the proper description"
#         have: tables
#         want: desc
# Failed test 140: "hasnt_view(sch, non-existent view) should have the proper description"
#         have: __SDFSDFD__
#         want: View "foo.__SDFSDFD__" should not exist
# Looks like you planned 896 tests but ran 893

@nasbyj
Copy link
Collaborator

nasbyj commented Jan 8, 2020

For one, you subtly changed the test; it used to explicitly test the description field in both cases, now it doesn't.

More importantly, you're changing the calling behavior. Currently, we have:

~@88e9fe532b8f.ant/87749# \df has_view
                         List of functions
 Schema |   Name   | Result data type | Argument data types | Type
--------+----------+------------------+---------------------+------
 public | has_view | text             | name                | func
 public | has_view | text             | name, name, text    | func
 public | has_view | text             | name, text          | func
(3 rows)

Which ensures that the 3 different functions can be uniquely distinguished by the database just by looking at the number of arguments. Your patch is adding a (name, name) function, which can not be readily distinguished from the (name, text) version. A quick test on 11 looks like the engine will default to (name, text), preserving existing behavior, but we need to have explicit tests for that.

@Godwottery
Copy link
Contributor Author

As far as I could tell, has_table has the same problem type. There are (name, text) and (name, name).
I think that the tests indicate that the text one is the default one. The name version is tested with a '::name' typecast.

@Godwottery
Copy link
Contributor Author

Godwottery commented Jan 14, 2020

Using the ::name typecast works for old versions of PostgreSQL (9.1 and 9.2)
This does not work for newer versions.

I think this confirms findings of @nasbyj. The (name, text) seems to be prefered.
I would like to argue that there is explicit tests for this -
has_view( 'pg_tables', 'yowza') should return 'yowza' if (name, text) is run. That is explicitly tested for.

Are there any ideas on why the explicitly typecast versions are not begin run correctly?

text seems to be the preferred datatype. Use select typname, typispreferred from pg_type where typcategory = 'S'; to check this. I could not find any 9.1 installation, but checked on 11 and 8.4 where text is preferred.

@nasbyj
Copy link
Collaborator

nasbyj commented Jan 16, 2020

I think you're mis-reading the test output (which is super-easy to do). The clue is at the very end:

These test targets failed: 'clean updatecheck'

If you search for "updatecheck" in the test output you'll find the section where that actually runs, and that's where the failures are, which actually makes perfect sense because you haven't added an update script for doing ALTER EXTENSION pgtap UPDATE.

This is a bit of a failing in our release process... after we tag a release we should really increment the version number and create the relevant pgtap--x.x.x--y.y.y.sql file in sql/. I'll go do that in master tomorrow. If you merge that change and then add the new functions to sql/pgtap--1.1.0--1.2.0.sql then tests should start passing.

(The reason 9.1 and 9.2 tests are passing is because ALTER EXTENSION UPDATE didn't exist back then, so we don't test updates there.)

@nasbyj
Copy link
Collaborator

nasbyj commented Jan 16, 2020

I've committed the necessary changes to master; please merge. You'll get a conflict on the update script; please keep the definition for pgtap_version() at the top of the file.

@Godwottery
Copy link
Contributor Author

That fixed the tests. Thanks for the help.

@nasbyj nasbyj merged commit cd178fe into theory:master Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants