sql

package
v0.28.0 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2020 License: BSD-3-Clause Imports: 9 Imported by: 0

README

Venom - Executor SQL

Step to execute SQL queries into MySQL and PostgreSQL databases.

It use the package sqlx under the hood: https://github.com/jmoiron/sqlx to retreive rows as a list of map[string]interface{}

Input

In your yaml file, you declare tour step like this

  - driver mandatory [mysql/postgres]
  - 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):


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: Title of TestSuite
testcases:

  - name: Query database
    steps:
      - type: sql
        database: mysql
        dsn: user:password@(localhost:3306)/venom
        file: ./test.sql
        assertions:
          - result.queries.__len__ ShouldEqual 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(testCaseContext venom.TestCaseContext, l venom.Logger, step venom.TestStep, workdir string) (venom.ExecutorResult, error)

Run implements the venom.Executor interface for Executor.

func (Executor) ZeroValueResult

func (Executor) ZeroValueResult() venom.ExecutorResult

ZeroValueResult return an empty implemtation 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 {
	Executor Executor      `json:"executor,omitempty" yaml:"executor,omitempty"`
	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