readfile

package
v1.0.0-rc.2 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2021 License: Apache-2.0 Imports: 14 Imported by: 5

README

Venom - Executor Read file

Step for Read file

Use case: you software write a file. Venom checks that file is produced, read it, and return content. Content can be used by another steps of testsuite.

Path can contains a fullpath, a wildcard or a directory:

- path: /a/full/path/file.txt
- path: afile.txt
- path: *.yml
- path: a_directory/
- path: ./foo/b*/**/z*.txt

Input

name: TestSuite Read File
testcases:
- name: TestCase Read File
  steps:
  - type: readfile
    path: yourfile.txt
    assertions:
    - result.err ShouldBeEmpty

Output

  result.timeseconds
  result.content
  result.contentjson
  result.size.filename
  result.md5sum.filename
  result.modtime.filename
  result.mod.filename
  • result.timeseconds: execution duration
  • result.err: if exist, this field contains error
  • result.content: content of readed file
  • result.contentjson: content of readed file if it's a json. You can access json data as result.contentjson.yourkey for example
  • result.size.filename: size of file 'filename'
  • result.md5sum.filename: md5 of file 'fifename'
  • result.modtime.filename: date modification of file 'filename', example: 1487698253
  • result.mod.filename: rights on file 'filename', example: -rw-r--r--

Default assertion

result.err ShouldBeEmpty

Example

testa.txt file:

simple content
multilines

testa.json file:

{
  "foo": "bar"
}

testb.json file:

[
  {
    "foo": "bar",
    "foo2": "bar2"
  }
]

venom test file:

name: TestSuite Read File
testcases:
- name: TestCase Read File
  steps:
  - type: readfile
    path: testa.json
    assertions:
      - result.contentjson.foo ShouldEqual bar

  - type: readfile
    path: testb.json
    assertions:
      - result.contentjson.contentjson0.foo2 ShouldEqual bar2

  - type: readfile
    path: test.txt
    assertions:
      - result.content ShouldContainSubstring multilines

Documentation

Index

Constants

View Source
const Name = "readfile"

Name for test readfile

Variables

This section is empty.

Functions

func New

func New() venom.Executor

New returns a new Test Exec

Types

type Executor

type Executor struct {
	Path string `json:"path,omitempty" yaml:"path,omitempty"`
}

Executor represents a Test Exec

func (Executor) GetDefaultAssertions

func (Executor) GetDefaultAssertions() *venom.StepAssertions

GetDefaultAssertions return default assertions for type exec

func (Executor) Run

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

Run execute TestStep of type exec

func (Executor) ZeroValueResult added in v0.17.0

func (Executor) ZeroValueResult() interface{}

ZeroValueResult return an empty implementation of this executor result

type Result

type Result struct {
	Content     string            `json:"content,omitempty" yaml:"content,omitempty"`
	ContentJSON interface{}       `json:"contentjson,omitempty" yaml:"contentjson,omitempty"`
	Err         string            `json:"error" yaml:"error"`
	TimeSeconds float64           `json:"timeSeconds,omitempty" yaml:"timeSeconds,omitempty"`
	Md5sum      map[string]string `json:"md5sum,omitempty" yaml:"md5sum,omitempty"`
	Size        map[string]int64  `json:"size,omitempty" yaml:"size,omitempty"`
	ModTime     map[string]int64  `json:"modtime,omitempty" yaml:"modtime,omitempty"`
	Mod         map[string]string `json:"mod,omitempty" yaml:"mod,omitempty"`
}

Result represents a step result

Jump to

Keyboard shortcuts

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