aferoassert

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 24, 2022 License: MIT Imports: 14 Imported by: 1

README

Assert with spf13/afero

GitHub Releases Build Status codecov Go Report Card GoDevDoc Donate

The logic is shamelessly copy from stretchr/testify/assert with some salt and pepper.

Prerequisites

  • Go >= 1.17

Install

go get go.nhat.io/aferoassert

Usage

package mypackage_test

import (
	"testing"

	"github.com/spf13/afero"
	"go.nhat.io/aferoassert"
)

func TestTreeEqual_Success(t *testing.T) {
	osFs := afero.NewOsFs()

	tree := `
- workflows:
    - golangci-lint.yaml
    - test.yaml 'perm:"0644"'
`

	aferoassert.DirExists(t, osFs, ".github")
	aferoassert.YAMLTreeEqual(t, osFs, tree, ".github")
}

Donation

If this project help you reduce time to develop, you can give me a cup of coffee :)

Paypal donation

paypal

       or scan this

Documentation

Overview

Package aferoassert provides assertions for spf13/afero

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrFileNameEmpty indicates that the file name is empty.
	ErrFileNameEmpty = errors.New("file name is empty")
	// ErrInvalidFileTreeFormat indicates that format of the file tree is invalid and could not be parsed.
	ErrInvalidFileTreeFormat = errors.New("invalid file tree format")
	// ErrInvalidFileMode indicates that the file mode is invalid.
	ErrInvalidFileMode = errors.New("invalid file mode")
)

Functions

func DirExists

func DirExists(t TestingT, fs afero.Fs, path string, msgAndArgs ...interface{}) bool

DirExists checks whether a directory exists in the given path. It also fails if the path is a file rather a directory or there is an error checking whether it exists.

func Exists

func Exists(t TestingT, fs afero.Fs, path string, msgAndArgs ...interface{}) bool

Exists checks whether a file or directory exists in the given path. It also fails if there is an error when trying to check the file.

func FileContent

func FileContent(t TestingT, fs afero.Fs, path string, expected string, msgAndArgs ...interface{}) bool

FileContent checks whether a file content is as expected or not.

func FileContentRegexp

func FileContentRegexp(t TestingT, fs afero.Fs, path string, expected interface{}, msgAndArgs ...interface{}) bool

FileContentRegexp checks whether a file content matches the expectation or not.

func FileExists

func FileExists(t TestingT, fs afero.Fs, path string, msgAndArgs ...interface{}) bool

FileExists checks whether a file exists in the given path. It also fails if the path points to a directory or there is an error when trying to check the file.

func FileModeFromUint64

func FileModeFromUint64(mode uint64) *os.FileMode

FileModeFromUint64 returns *os.FileMode from an uint64.

func FileModePtr

func FileModePtr(mode os.FileMode) *os.FileMode

FileModePtr returns pointer to file mode.

func NoDirExists

func NoDirExists(t TestingT, fs afero.Fs, path string, msgAndArgs ...interface{}) bool

NoDirExists checks whether a directory does not exist in the given path. It fails if the path points to an existing _directory_ only.

func NoExists

func NoExists(t TestingT, fs afero.Fs, path string, msgAndArgs ...interface{}) bool

NoExists checks whether a file does not exist in a given path.

func NoFileExists

func NoFileExists(t TestingT, fs afero.Fs, path string, msgAndArgs ...interface{}) bool

NoFileExists checks whether a file does not exist in a given path. It fails if the path points to an existing _file_ only.

func Perm

func Perm(t TestingT, fs afero.Fs, path string, expected os.FileMode, msgAndArgs ...interface{}) bool

Perm checks whether a path has the expected permission or not.

func TreeContains

func TreeContains(t TestingT, fs afero.Fs, tree FileTree, path string, msgAndArgs ...interface{}) bool

TreeContains checks whether a directory contains a file tree or not.

func TreeEqual

func TreeEqual(t TestingT, fs afero.Fs, tree FileTree, path string, msgAndArgs ...interface{}) bool

TreeEqual checks whether a directory is the same as the expectation or not.

func YAMLTreeContains

func YAMLTreeContains(t TestingT, fs afero.Fs, expected, path string, msgAndArgs ...interface{}) bool

YAMLTreeContains checks whether a directory contains a file tree or not.

func YAMLTreeEqual

func YAMLTreeEqual(t TestingT, fs afero.Fs, expected, path string, msgAndArgs ...interface{}) bool

YAMLTreeEqual checks whether a directory is the same as the expectation or not.

Types

type FileModeTags

type FileModeTags map[string]*os.FileMode

FileModeTags is a list of tagged file mode.

func (FileModeTags) Mode

func (t FileModeTags) Mode() *os.FileMode

Mode returns file mode.

func (FileModeTags) Perm

func (t FileModeTags) Perm() *os.FileMode

Perm returns perm file mode.

func (FileModeTags) String

func (t FileModeTags) String() string

String returns tags in struct tag format.

func (FileModeTags) Type

func (t FileModeTags) Type() *os.FileMode

Type returns type file mode.

type FileNode

type FileNode struct {
	Name     string
	Tags     FileModeTags
	Children FileTree
	// contains filtered or unexported fields
}

FileNode contains needed information for assertions.

func (FileNode) Flatten

func (n FileNode) Flatten(root string) map[string]FileNode

Flatten converts the file tree to a flat map, key is the path to file.

func (FileNode) MarshalYAML

func (n FileNode) MarshalYAML() (interface{}, error)

MarshalYAML satisfies yaml.Marshaler.

func (*FileNode) UnmarshalYAML

func (n *FileNode) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies yaml.Unmarshaler.

type FileTree

type FileTree map[string]FileNode

FileTree is a map of node.

func (FileTree) Flatten

func (t FileTree) Flatten(root string) map[string]FileNode

Flatten converts the file tree to a flat map, key is the path to file.

func (FileTree) MarshalYAML

func (t FileTree) MarshalYAML() (interface{}, error)

MarshalYAML satisfies yaml.Marshaler.

func (*FileTree) UnmarshalYAML

func (t *FileTree) UnmarshalYAML(value *yaml.Node) error

UnmarshalYAML satisfies yaml.Unmarshaler.

type TestingT

type TestingT interface {
	Errorf(format string, args ...interface{})
}

TestingT is an interface wrapper around *testing.T.

Jump to

Keyboard shortcuts

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