testing

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: May 23, 2023 License: BSD-3-Clause Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultText string = `
Some text.
`
View Source
const PackageYamlText string = `
name: package-name
title: PackageTitle
author: package-author
`
View Source
const TIMESTAMP_REGEX string = `\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?([+-]\d{2}:\d{2})?[Zz]?`

Variables

View Source
var BootCmdEquals Checker = &bootCmdEqualsChecker{
	&CheckerInfo{Name: "BootCmdEquals", Params: []string{"obtained", "bootcmd", "env"}},
}

The BootCmdEquals checker verifies that the bootCmd string (possibly with --env prefixes) matches the expected boot command and environment variables. Three arguments are required to the right of the checker: - bootCmd string that contains only the bootcmd without --env prefixes - env map[string]string that defines expected environment variables - soft bool that switches between '=' (when false) and '?=' (when true) operator

For example:

c.Assert("--env=A=1 /node server.js", BootCmdEquals, "/node server.js", map[string]string{"A": "1"}, true)
View Source
var CmdOutputMatches Checker = &cmdOutputMatchesChecker{
	&CheckerInfo{Name: "CmdOutputMatches", Params: []string{"cmd", "expected"}},
}

The CmdOutputMatches checker invokes bash command and checks if stdout matches.

For example:

c.Check([]string{"echo", "Hello!"}, CmdOutputMatches, "Hello!")
View Source
var ContainsArray Checker = &containsArrayChecker{
	&CheckerInfo{Name: "ContainsArray", Params: []string{"obtained", "subarray"}},
}

The ContainsArray checker verifies that the obtained array contains the expected subarray.

For example:

c.Assert([]string{"a", "b", "c"}, ContainsArray, []string{"a", "b"})      # TRUE
c.Assert([]string{"a", "b", "c"}, ContainsArray, []string{"b", "c"})      # TRUE
c.Assert([]string{"a", "b", "c"}, ContainsArray, []string{"b"})           # TRUE
c.Assert([]string{"a", "b", "c"}, ContainsArray, []string{"c", "b", "a"}) # FALSE
c.Assert([]string{"a", "b", "c"}, ContainsArray, []string{"a", "c"})      # FALSE
c.Assert([]string{"a", "b", "c"}, ContainsArray, []string{"x"})           # FALSE
c.Assert([]string{"a", "b", "c"}, ContainsArray, []string{})              # FALSE
View Source
var DirEquals Checker = &dirEqualsChecker{
	&CheckerInfo{Name: "DirEquals", Params: []string{"obtained", "expected"}},
}

DirEquals checker checks that given directory contains exactly given files with given content. Argument 'expected' must be a map[string]interface{} where key is path of the file and value is one of type:

  • string - file content must match exactly for checker to succed
  • func(string)error- file content is passed to this function and it must return nil for checker to succeed

For example:

c.Assert("/tmp/mydir", DirEquals, map[string]string{"/file01.txt": "Exact content"})
c.Assert("/tmp/mydir", DirEquals, map[string]string{"/file01.txt": func(val string)error{return nil}})
View Source
var FileMatches Checker = &fileMatchesChecker{
	&CheckerInfo{Name: "FileMatches", Params: []string{"obtained", "expected"}},
}

FileMatches checker checks that given file contains given regexp.

For example:

c.Assert("/tmp/myfile", FileMatches, "Part of the content.+")
View Source
var MatchesMultiline Checker = &matchesMultilineChecker{
	&CheckerInfo{Name: "Matches", Params: []string{"value", "regex"}},
}

The MatchesMultiline checker verifies that the string provided as the obtained value (or the string resulting from obtained.String()) matches the regular expression provided and is matched against multiline string.

For example:

c.Assert(v, Matches, "perm.*denied")
View Source
var TarGzEquals Checker = &tarGzEqualsChecker{
	&CheckerInfo{Name: "TarGzEquals", Params: []string{"obtained", "expected"}},
}

TarGzEquals checker checks that given tar.gz archive contains exactly given files with given content. Argument 'expected' must be a map[string]interface{} where key is path of the file and value is one of type:

  • string - file content must match exactly for checker to succed
  • func(string)error- file content is passed to this function and it must return nil for checker to succeed

For example:

c.Assert("/tmp/archive.tar.gz", TarGzEquals, map[string]string{"/file01.txt": "Exact content"})
c.Assert("/tmp/archive.tar.gz", TarGzEquals, map[string]string{"/file01.txt": func(val string)error{return nil}})

Functions

func CheckBootCmd

func CheckBootCmd(obtained, bootCmd string, env []string) error

func ClearDirectory

func ClearDirectory(directory string)

func FixIndent

func FixIndent(s string) string

FixIndent moves the inline yaml content to the very left. This way we are able to write inline yaml content that is nicely aligned with other code.

func MockGitHubApiServer

func MockGitHubApiServer() *httptest.Server

func PrepareFiles

func PrepareFiles(directory string, files map[string]string) error

PrepareFiles realizes map[filepath]content into given directory. E.g. directory = /tmp/sample, files = {"/file01.txt" => "Foo Bar"} will result in

/tmp/sample/

|- file01.txt

where file01.txt will contain text content of "Foo Bar".

Types

This section is empty.

Jump to

Keyboard shortcuts

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