readfile

package
v0.23.1 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2018 License: BSD-3-Clause Imports: 13 Imported by: 0

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 ShouldNotExist

Output

  result.timeseconds
  result.timehuman
  result.executor.executor.path
  result.content
  result.contentjson
  result.size.filename
  result.md5sum.filename
  result.modtime.filename
  result.mod.filename
  • result.timeseconds & result.timehuman: time for read file
  • result.executor.path: executor condition with file path
  • 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 ShouldNotExist

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(testCaseContext venom.TestCaseContext, l venom.Logger, step venom.TestStep, workdir string) (venom.ExecutorResult, error)

Run execute TestStep of type exec

func (Executor) ZeroValueResult added in v0.17.0

func (Executor) ZeroValueResult() venom.ExecutorResult

ZeroValueResult return an empty implemtation of this executor result

type Result

type Result struct {
	Executor    Executor          `json:"executor,omitempty" yaml:"executor,omitempty"`
	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"`
	TimeHuman   string            `json:"timeHuman,omitempty" yaml:"timeHuman,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