assert

package
v1.0.7 Latest Latest
Warning

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

Go to latest
Published: Dec 16, 2024 License: MIT Imports: 2 Imported by: 0

README

Assertion

This is a flexible and extensible assertion library designed to provide a unified interface for asserting conditions in Go tests. It allows developers to seamlessly integrate assertion functionality into their tests without being tied to a specific assertion library.



Features

  • General assertion interface for asserting conditions in tests.
  • Supports various assertion functions for different types of conditions.
  • Easy-to-use assertion functions for consistent handling of assertions in tests.

Installation

To install the assertion library, use the following command:

go get oss.nandlabs.io/golly/testing/assert

Usage

  1. Import the library into your Go test file:
    import "oss.nandlabs.io/golly/testing/assert"
    
  2. Use the assertion functions in your test cases. For example:
    func TestAdd(t *testing.T) {
        result := add(1, 2)
        assert.Equal(t, result, 3)
    }
    
  3. Run your tests using the go test command:
    go test
    
  4. View the test results and assertions in the test output.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Empty added in v1.0.1

func Empty(t *testing.T, obj any) bool

Empty checks if an array is empty

func Equal

func Equal(t *testing.T, expected, actual any) bool

Equal compares the expected and actual values and logs an error if they are not equal

func Error

func Error(t *testing.T, err error)

Error logs an error if the error is nil

func False

func False(t *testing.T, condition bool) bool

False logs an error if the condition is true

func HasKey

func HasKey(t *testing.T, m map[string]any, key string) bool

HasKey logs an error if the key is not a member of the map

func HasValue

func HasValue(t *testing.T, m map[string]any, value any) bool

HasValue logs an error if the value is not a member of the map

func Len added in v1.0.1

func Len(t *testing.T, obj any, length int) bool

Len checks if the length of the array is equal to the expected length

func ListHas

func ListHas[S ~[]E, E any](t *testing.T, value any, list S) bool

ListHas logs an error if the list does not contain the value

func ListMissing

func ListMissing[S ~[]E, E any](t *testing.T, value any, list S) bool

ListMissing logs an error if the list contains the value

func MapContains

func MapContains(t *testing.T, m map[string]any, key string, value any) bool

MapContains logs an error if the map does not contain the key-value pair

func MapMissing

func MapMissing(t *testing.T, m map[string]any, key string, value any) bool

MapMissing logs an error if the map contains the key-value pair

func Nil

func Nil(t *testing.T, value any) bool

Nil logs an error if the value is not nil

func NoError

func NoError(t *testing.T, err error) bool

NoError logs an error if the error is not nil

func NotEmpty added in v1.0.2

func NotEmpty(t *testing.T, obj any) bool

NotEmpty checks if an array is not empty

func NotEqual

func NotEqual(t *testing.T, expected, actual any) bool

NotEqual compares the expected and actual values and logs an error if they are equal

func NotNil

func NotNil(t *testing.T, value any) bool

NotNil logs an error if the value is nil

func True

func True(t *testing.T, condition bool) bool

True logs an error if the condition is false

Types

This section is empty.

Jump to

Keyboard shortcuts

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