Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

github.com/seiyab/teq

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/seiyab/teq

  • v0.2.0
  • Source
  • Go
  • Socket score

Version published
Created
Source

teq

CI

teq is a Go library designed to enhance your testing experience by providing a flexible and customizable way to perform deep equality checks. It's especially useful when you need to compare complex objects or types that have specific equality conditions.

Features

  • Transforms: Register a "transform" function that can modify objects before comparison. This allows you to control how equality is determined. For example, by transforming time.Time objects to UTC, you can make your equality checks timezone-insensitive.
  • Formats: Register a "format" function that defines how objects are displayed when they are not equal. This is useful for types like time.Time and decimal.Decimal that may not be human-readable in their default format. By registering your own format, you can make the output of your tests more understandable.

Installation

go get github.com/seiyab/teq@latest

Usage

To use teq, you first need to create a new instance:

tq := teq.New()

Then, you can add your transforms and formats:

// time.Time will be transformed into UTC time. So equality check with `tq` will be timezone-insensitive.
tq.AddTransform(func(d time.Time) time.Time {
    return d.In(d.UTC)
})

// time.Time will be shown in RFC3339 format when it appear in diff.
tq.AddFormat(func(d time.Time) string {
    return d.Format(time.RFC3339)
})

Finally, you can use teq to perform deep equality checks in your tests:

tq.Equal(t, expected, actual)

If you need "common" equality across your project, we recommend to define function that returns your customized teq.

func NewTeq() teq.Teq {
    tq := teq.New()
    tq.AddTransform(/* ... */)
    tq.AddTransform(/* ... */)
    // :
    return tq
}

// then you can easily use it everywhere
tq := NewTeq()

Prior works

  • testify
  • deepequal.go in "github.com/weaveworks/scope/test/reflect" package authored by Weaveworks Ltd
  • go-cmp

FAQs

Package last updated on 07 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc