Обсуждение: Inappropriate failure conditions in foreign_data regression test

Поиск
Список
Период
Сортировка

Inappropriate failure conditions in foreign_data regression test

От
Tom Lane
Дата:
By chance I noticed that the foreign_data regression test fails if run
in an installation where "bob" is a live user.  It appears to be
assuming that half a dozen other fairly common names don't belong to
real users, either.  Could we make this a little less fragile?  Maybe
call them no_such_user_N.  Or for that matter do we really need quite
so many tests of the same error condition?
        regards, tom lane


Re: Inappropriate failure conditions in foreign_data regression test

От
Martin Pihlak
Дата:
> By chance I noticed that the foreign_data regression test fails if run
> in an installation where "bob" is a live user.  It appears to be
> assuming that half a dozen other fairly common names don't belong to
> real users, either.  Could we make this a little less fragile?  Maybe

Attached is a patch that attempts to fix that -- user mappings are now
created for "regress_test_missing_role" instead of "bob" or "baz".

> call them no_such_user_N.  Or for that matter do we really need quite
> so many tests of the same error condition?
>

The code paths leading to those error conditions are different (or at
least they should be). The initial aim was to get as much test coverage
as possible, but I guess the tests could be simplified if this is turning
out to be a maintenance burden

regards,
Martin

*** a/src/test/regress/expected/foreign_data.out
--- b/src/test/regress/expected/foreign_data.out
***************
*** 524,531 **** List of user mappings
  (0 rows)

  -- CREATE USER MAPPING
! CREATE USER MAPPING FOR baz SERVER s1;                      -- ERROR
! ERROR:  role "baz" does not exist
  CREATE USER MAPPING FOR current_user SERVER s1;             -- ERROR
  ERROR:  server "s1" does not exist
  CREATE USER MAPPING FOR current_user SERVER s4;
--- 524,531 ----
  (0 rows)

  -- CREATE USER MAPPING
! CREATE USER MAPPING FOR regress_test_missing_role SERVER s1;  -- ERROR
! ERROR:  role "regress_test_missing_role" does not exist
  CREATE USER MAPPING FOR current_user SERVER s1;             -- ERROR
  ERROR:  server "s1" does not exist
  CREATE USER MAPPING FOR current_user SERVER s4;
***************
*** 565,572 **** RESET ROLE;
  (7 rows)

  -- ALTER USER MAPPING
! ALTER USER MAPPING FOR bob SERVER s4 OPTIONS (gotcha 'true');   -- ERROR
! ERROR:  role "bob" does not exist
  ALTER USER MAPPING FOR user SERVER ss4 OPTIONS (gotcha 'true'); -- ERROR
  ERROR:  server "ss4" does not exist
  ALTER USER MAPPING FOR public SERVER s5 OPTIONS (gotcha 'true');            -- ERROR
--- 565,572 ----
  (7 rows)

  -- ALTER USER MAPPING
! ALTER USER MAPPING FOR regress_test_missing_role SERVER s4 OPTIONS (gotcha 'true'); -- ERROR
! ERROR:  role "regress_test_missing_role" does not exist
  ALTER USER MAPPING FOR user SERVER ss4 OPTIONS (gotcha 'true'); -- ERROR
  ERROR:  server "ss4" does not exist
  ALTER USER MAPPING FOR public SERVER s5 OPTIONS (gotcha 'true');            -- ERROR
***************
*** 595,608 **** RESET ROLE;
  (7 rows)

  -- DROP USER MAPPING
! DROP USER MAPPING FOR bob SERVER s4;                        -- ERROR
! ERROR:  role "bob" does not exist
  DROP USER MAPPING FOR user SERVER ss4;
  ERROR:  server "ss4" does not exist
  DROP USER MAPPING FOR public SERVER s7;                     -- ERROR
  ERROR:  user mapping "public" does not exist for the server
! DROP USER MAPPING IF EXISTS FOR bob SERVER s4;
! NOTICE:  role "bob" does not exist, skipping
  DROP USER MAPPING IF EXISTS FOR user SERVER ss4;
  NOTICE:  server does not exist, skipping
  DROP USER MAPPING IF EXISTS FOR public SERVER s7;
--- 595,608 ----
  (7 rows)

  -- DROP USER MAPPING
! DROP USER MAPPING FOR regress_test_missing_role SERVER s4;  -- ERROR
! ERROR:  role "regress_test_missing_role" does not exist
  DROP USER MAPPING FOR user SERVER ss4;
  ERROR:  server "ss4" does not exist
  DROP USER MAPPING FOR public SERVER s7;                     -- ERROR
  ERROR:  user mapping "public" does not exist for the server
! DROP USER MAPPING IF EXISTS FOR regress_test_missing_role SERVER s4;
! NOTICE:  role "regress_test_missing_role" does not exist, skipping
  DROP USER MAPPING IF EXISTS FOR user SERVER ss4;
  NOTICE:  server does not exist, skipping
  DROP USER MAPPING IF EXISTS FOR public SERVER s7;
*** a/src/test/regress/sql/foreign_data.sql
--- b/src/test/regress/sql/foreign_data.sql
***************
*** 204,210 **** DROP SERVER s3 CASCADE;
  \deu

  -- CREATE USER MAPPING
! CREATE USER MAPPING FOR baz SERVER s1;                      -- ERROR
  CREATE USER MAPPING FOR current_user SERVER s1;             -- ERROR
  CREATE USER MAPPING FOR current_user SERVER s4;
  CREATE USER MAPPING FOR user SERVER s4;                     -- ERROR duplicate
--- 204,210 ----
  \deu

  -- CREATE USER MAPPING
! CREATE USER MAPPING FOR regress_test_missing_role SERVER s1;  -- ERROR
  CREATE USER MAPPING FOR current_user SERVER s1;             -- ERROR
  CREATE USER MAPPING FOR current_user SERVER s4;
  CREATE USER MAPPING FOR user SERVER s4;                     -- ERROR duplicate
***************
*** 228,234 **** RESET ROLE;
  \deu

  -- ALTER USER MAPPING
! ALTER USER MAPPING FOR bob SERVER s4 OPTIONS (gotcha 'true');   -- ERROR
  ALTER USER MAPPING FOR user SERVER ss4 OPTIONS (gotcha 'true'); -- ERROR
  ALTER USER MAPPING FOR public SERVER s5 OPTIONS (gotcha 'true');            -- ERROR
  ALTER USER MAPPING FOR current_user SERVER s8 OPTIONS (username 'test');    -- ERROR
--- 228,234 ----
  \deu

  -- ALTER USER MAPPING
! ALTER USER MAPPING FOR regress_test_missing_role SERVER s4 OPTIONS (gotcha 'true'); -- ERROR
  ALTER USER MAPPING FOR user SERVER ss4 OPTIONS (gotcha 'true'); -- ERROR
  ALTER USER MAPPING FOR public SERVER s5 OPTIONS (gotcha 'true');            -- ERROR
  ALTER USER MAPPING FOR current_user SERVER s8 OPTIONS (username 'test');    -- ERROR
***************
*** 241,250 **** RESET ROLE;
  \deu+

  -- DROP USER MAPPING
! DROP USER MAPPING FOR bob SERVER s4;                        -- ERROR
  DROP USER MAPPING FOR user SERVER ss4;
  DROP USER MAPPING FOR public SERVER s7;                     -- ERROR
! DROP USER MAPPING IF EXISTS FOR bob SERVER s4;
  DROP USER MAPPING IF EXISTS FOR user SERVER ss4;
  DROP USER MAPPING IF EXISTS FOR public SERVER s7;
  CREATE USER MAPPING FOR public SERVER s8;
--- 241,250 ----
  \deu+

  -- DROP USER MAPPING
! DROP USER MAPPING FOR regress_test_missing_role SERVER s4;  -- ERROR
  DROP USER MAPPING FOR user SERVER ss4;
  DROP USER MAPPING FOR public SERVER s7;                     -- ERROR
! DROP USER MAPPING IF EXISTS FOR regress_test_missing_role SERVER s4;
  DROP USER MAPPING IF EXISTS FOR user SERVER ss4;
  DROP USER MAPPING IF EXISTS FOR public SERVER s7;
  CREATE USER MAPPING FOR public SERVER s8;

Re: Inappropriate failure conditions in foreign_data regression test

От
Alvaro Herrera
Дата:
Martin Pihlak escribió:
> > By chance I noticed that the foreign_data regression test fails if run
> > in an installation where "bob" is a live user.  It appears to be
> > assuming that half a dozen other fairly common names don't belong to
> > real users, either.  Could we make this a little less fragile?  Maybe
> 
> Attached is a patch that attempts to fix that -- user mappings are now
> created for "regress_test_missing_role" instead of "bob" or "baz".

Applied, thanks.

-- 
Alvaro Herrera                                http://www.CommandPrompt.com/
PostgreSQL Replication, Consulting, Custom Development, 24x7 support