sql

package
v1.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 28, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

README

Venom - Executor SQL

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{}

Input

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 if commands 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

SQL drivers

This executor uses the following SQL drivers:

Documentation

Index

Constants

View Source
const Name = "sql"

Name of the executor.

Variables

This section is empty.

Functions

func New

func New() venom.Executor

New returns a new executor that can execute SQL queries

Types

type Executor

type Executor struct {
	File     string   `json:"file,omitempty" yaml:"file,omitempty"`
	Commands []string `json:"commands,omitempty" yaml:"commands,omitempty"`
	Driver   string   `json:"driver" yaml:"driver"`
	DSN      string   `json:"dsn" yaml:"dsn"`
}

Executor is a venom executor can execute SQL queries

func (Executor) GetDefaultAssertions

func (e Executor) GetDefaultAssertions() venom.StepAssertions

GetDefaultAssertions return the default assertions of the executor.

func (Executor) Run

func (e Executor) Run(ctx context.Context, step venom.TestStep) (interface{}, error)

Run implements the venom.Executor interface for Executor.

func (Executor) ZeroValueResult

func (Executor) ZeroValueResult() interface{}

ZeroValueResult return an empty implementation of this executor result

type QueryResult

type QueryResult struct {
	Rows Rows `json:"rows,omitempty" yaml:"rows,omitempty"`
}

QueryResult represents a rows return by a SQL query execution.

type Result

type Result struct {
	Queries []QueryResult `json:"queries,omitempty" yaml:"queries,omitempty"`
}

Result represents a step result.

type Row

type Row map[string]interface{}

Row represents a row return by a SQL query.

type Rows

type Rows []Row

Rows represents an array of Row

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL