Giter Site home page Giter Site logo

wall clock about testify HOT 10 CLOSED

yonesko avatar yonesko commented on June 15, 2024
wall clock

from testify.

Comments (10)

brackendawson avatar brackendawson commented on June 15, 2024 3

Testify is correct, they are not equal. The behaviour of actual is demonstrably different to the behaviour of expected.

If you only care that they have the same time, then use WithinDuration:

package main

import (
	"encoding/json"
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
)

type A struct {
	T time.Time
}

func Test(t *testing.T) {
	now := time.Now()
	a := A{T: now}
	marshal, _ := json.Marshal(a)
	var aParsed A
	json.Unmarshal(marshal, &aParsed)
	assert.WithinDuration(t, a.T, aParsed.T, 0)
}

from testify.

brackendawson avatar brackendawson commented on June 15, 2024 2

How to compare not times but a structure with time fields ?

You'll need to either test the fields individually or write an equality test helper function for your struct, for what you consider to be equal. time.Time values are not the only examply where this becomes necessary, another common one is slice type fields where you only care about the elements matching and not the order. The fields literally aren't equal but you can't use EqualElements on a struct.

Another option may be to use time.Now().Truncate(0) as your test input, this strips the wall time.

I'm afraid we can't call this a bug because the behaviour of Equal is as documented according to the package docs and the Go spec, and to change the bahaviour would be a breaking change. What if someone's test depends on the wall time difference between time.Time values?

If you can reason that this change should be made, or you can propose a good design for a compatible change that isn't assert.SortOfEqual please comment and I will re-open the issue.

from testify.

dolmen avatar dolmen commented on June 15, 2024

I don't understand your issue. Please post a self-contained example that reproduces your issue using this template: https://go.dev/play/p/AsRNcxCRdWx

from testify.

yonesko avatar yonesko commented on June 15, 2024

I have updated the first comment

from testify.

dolmen avatar dolmen commented on June 15, 2024

The Testify API is very comprehensive. Have you tried the other Equal functions? Please expand your test code to show the issue you have with the other functions.

By the way, this isn't a support forum. Issues are for reporting bugs or discussing enhancements. There are more appropriate places for asking for help.

from testify.

yonesko avatar yonesko commented on June 15, 2024

This is not support^ this is bug

from testify.

tscales avatar tscales commented on June 15, 2024

similar issue as #1461. This should be resolved whenever a new release is cut.

from testify.

KKKZOZ avatar KKKZOZ commented on June 15, 2024

i have met with this too, please release a new package asap

from testify.

gabriel-vasile avatar gabriel-vasile commented on June 15, 2024

similar issue as #1461. This should be resolved whenever a new release is cut.

It's a little different. Here T time is a field in a struct, meaning the equality comparison defaults to reflect.DeepEqual.
New release will not fix this issue.

from testify.

yonesko avatar yonesko commented on June 15, 2024

How to compare not times but a structure with time fields ?

from testify.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.