Step to execute SQL queries into databases:
- MySQL
- PostgreSQL
- Oracle
- Sqlite
It use the package sqlx
under the hood: https://github.com/jmoiron/sqlx to retrieve rows as a list of map[string]interface{}
In your yaml file, you declare your step like this
- driver mandatory [mysql/postgres/oracle/sqlite]
- dsn mandatory
- commands optional
- file optional
commands
is a list of SQL queries.file
parameter is only used as a fallback ifcommands
is not used.
Example usage (mysql, oracle, SQLServer):
name: Title of TestSuite
testcases:
- name: Query database
steps:
- type: sql
driver: mysql
dsn: user:password@(localhost:3306)/venom
commands:
- "SELECT * FROM employee;"
- "SELECT * FROM person;"
assertions:
- result.queries.__Len__ ShouldEqual 2
- result.queries.queries0.rows.rows0.name ShouldEqual Jack
- result.queries.queries1.rows.rows0.age ShouldEqual 21
- name: Oracle
steps:
- type: sql
driver: oracle
dsn: "oracle://system:oracle@localhost:49161/XE"
commands:
- select * from v$version
Example with a query file:
name: Title of TestSuite
testcases:
- name: Query database
steps:
- type: sql
database: mysql
dsn: user:password@(localhost:3306)/venom
file: ./test.sql
assertions:
- result.queries ShouldHaveLength 1
*note: in the example above, the results of each command is stored in the results array
This executor uses the following SQL drivers:
- MySQL: https://github.com/go-sql-driver/mysql
- PostgreSQL: https://github.com/lib/pq
- Oracle: https://github.com/sijms/go-ora
- Sqlite: https://pkg.go.dev/modernc.org/sqlite