GithubHelp home page GithubHelp logo

moertel / squcumber-postgres Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 6.0 104 KB

Cucumber-based framework for defining and executing SQL unit, integration and acceptance tests for PostgreSQL databases

License: MIT License

Ruby 99.14% Dockerfile 0.86%
cucumber cucumber-framework postgresql postgrest sql test-automation test-driven-development test-framework

squcumber-postgres's Introduction

Hi, I'm Stefanie!   👾 》I automate ALL the things. GitOps & DataOps advocate. I test my code. Occasionally, I draw.


languages python go ruby scala     tools kubernetes docker spark vim git     worksat adobe

Senior Data & Platform Engineerworking in Data, Reliability Analytics & Automation
Digital Artist & Creatorspecialised in neo-noir pixel art animations and 8bit-ish art


Stefanie's Twitter Stefanie's Instagram Stefanie's LinkedIn Stefanie's Tumblr Stefanie's Behance

|     Website & Gallery : https://moer.tel    |    Open Source Work : ▼ ▼ ▼

squcumber-postgres's People

Contributors

moertel avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

squcumber-postgres's Issues

Parentheses "()" are being removed from table values

Given the existing table "some_table":
  | some_column |
  | foo (bar)   |
When the resulting table "some_table" is queried
Then the result exactly matches:
  | some_column |
  | foo (bar)   |

This fails with error:

Does not match exactly, got:
| some_column |
| foo         |
(RuntimeError)
./features/test.feature:1:in `Then the result exactly matches:'

Values with parentheses are just stripped from the table data.

Allow a table definition to be empty

Sometimes a table used in a query will be left empty in the scope of the test to check a particular behaviour of the SQL. Omitting the table from the test setup means that the fact of it being empty can be overlooked easily.

It would be beneficial to have a way to explicitly state a table as being empty.

Given the existing table "tracking.kpi" is empty

Single quotes need to be escaped

This test will throw a syntax error because of the single quotes:

Feature: Imma feature
  Background:
    Given the SQL files in the path "/sql":
      | file                      |
      | testing_things.sql        |
    And their table dependencies:
      | table                     |
      | schema.table            |


    Scenario: Adopted customer
      Given the existing table schema.table with date placeholders:
        | name |
	| This has 'quotes' | 
      When the given SQL files are executed and the result is returned
      Then the result exactly matches:
        | name |
        | This has 'quotes' |

ERROR: syntax error at or near "quotes" squcumber-app | LINE 1: ...sert into schema.table (name) values ('This has 'quotes'')

where name is varchar(255)

in order to make the test pass, we need to escape the quotes

Feature: Imma feature
  Background:
    Given the SQL files in the path "/sql":
      | file                      |
      | testing_things.sql        |
    And their table dependencies:
      | table                     |
      | schema.table            |


    Scenario: Adopted customer
      Given the existing table schema.table with date placeholders:
        | name |
	| This has ''quotes'' | 
      When the given SQL files are executed and the result is returned
      Then the result exactly matches:
        | name |
        | This has 'quotes' |

Non-existent column names silently ignored in "Then" steps

Only columns that are under test need to be specified in a result step. Should the actual result that is returned from a table or query have columns that are not included in the expected result, these will be silently ignored.

However, if a column in the specified expectetd result has a typo, then this will inadvertently be silently ignored as well, because we only take the keys from the actual result:

row.all? do |key, value|
values_match(value, hash[key]) # actual,expected
end

An error should be raised if a non-existent column name is specified in the expected result.

Add support for queries that don't create tables

Something along the lines of:

When(/^the given SQL files are executed and the result is kept$/) do
  silence_streams(STDERR) do
    @sql_files_to_execute.each do |file|
      sql = File.read(file)
      @result = TESTING_DATABASE.query(sql).map { |e| e }
    end
  end
end

Undefined method when using `Then the result exactly matches`

Using the following feature file:

Feature: This just tests having a UI for SQL testing

  Background:
    Given the SQL files in the path "/opt/sql":
      | file            |
      | temp.sql        |
    And their table dependencies:
      | table           |
      | some_table |

    
   Scenario: Test
    Given the existing table "some_table":
      | login_name |
      | test       |
    When the given SQL files are executed and the result is returned
    Then the result exactly matches:
      | login_name |
      | test       |

and the SQL

select * from some_table;

I get the following error:

Feature: This just tests having a UI for SQL testing

Background: # /opt/features/temp.feature:3
Given the SQL files in the path "/opt/sql": # squcumber-postgres-0.0.7/lib/squcumber-postgres/step_definitions/common_steps.rb:17
| file |
| temp.sql |
And their table dependencies: # squcumber-postgres-0.0.7/lib/squcumber-postgres/step_definitions/common_steps.rb:35
| table |
| some_table |

Scenario: Test # /opt/features/temp.feature:12
Given the existing table "some_table": # squcumber-postgres-0.0.7/lib/squcumber-postgres/step_definitions/common_steps.rb:67
| login_name |
| test |
When the given SQL files are executed and the result is returned # step_definitions/common_steps.rb:5
Then the result exactly matches: # squcumber-postgres-0.0.7/lib/squcumber-postgres/step_definitions/common_steps.rb:151
| login_name |
| test |
undefined method `values_match' for # (NoMethodError)
./features/temp.feature:17:in `Then the result exactly matches:'

This happens for both 0.0.6 and 0.0.7. The above scenario does use a custom step. However, a similar error occurs when using When the given SQL files are executed, but only on v0.0.7

Background: # /opt/features/temp.feature:3
Given the SQL files in the path "/opt/sql": # squcumber-postgres-0.0.7/lib/squcumber-postgres/step_definitions/common_steps.rb:17
| file |
| temp.sql |
And their table dependencies: # squcumber-postgres-0.0.7/lib/squcumber-postgres/step_definitions/common_steps.rb:35
| table |
| some_table |

Scenario: Test # /opt/features/temp.feature:12
Given the existing table "some_table": # squcumber-postgres-0.0.7/lib/squcumber-postgres/step_definitions/common_steps.rb:67
| login_name |
| test |
When the given SQL files are executed # squcumber-postgres-0.0.7/lib/squcumber-postgres/step_definitions/common_steps.rb:83
Then the result exactly matches: # squcumber-postgres-0.0.7/lib/squcumber-postgres/step_definitions/common_steps.rb:151
| login_name |
| test |
undefined method `length' for # (NoMethodError)
./features/temp.feature:17:in `Then the result exactly matches:'

Failing Scenarios:
cucumber /opt/features/temp.feature:12 # Scenario: Test

Edit by @grunwald: Anonymised table names to not leak business information.

Using the step`Given the existing table` results error if not defined in Background

Using the step Given the existing table "some_schema.some_table" will break if the table hasn't previously been defined in the Background step Given their table dependencies. This is not intuitive because the given step does imply that a fixture is added with it.

An obvious solution would be to add a table implicitly when that step is called.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.