Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a WithinTimes assertion #689

Conversation

goodspark
Copy link

I've been testing some code that generates timestamps and found that I'm often thinking in terms of 'time should be between a and b'. So I think this might be helpful.

Example of how I'd like to write my tests:

before := time.Now()
data := DoSomething()
after := time.Now()

assert.WithinTimes(t, before, data.timestamp, after)

Without this, I have to use WithinDuration, which I find slightly cumbersome to setup and read.

before := time.Now()
data := DoSomething()
span := time.Since(before) /2
midpoint := before.Add(span)

assert.WithinDuration(t, midpoint, data.timestamp, span)

I've been testing some code that generates timestamps and found that I'm often thinking in terms 'time should be between a and b'. So I think this might be helpful.

Example of how I've been writing my tests:

```go
before := time.Now()
data := DoSomething()
after := time.Now()

assert.WithinTimes(t, before, data.timestamp, after)
```

Without this, I have to use `WithinDuration`, which I find _slightly_ cumbersome to setup and read.

```go
before := time.Now()
data := DoSomething()
span := time.Since(before) /2
midpoint := before.Add(span)

assert.WithinDuration(t, midpoint, data.timestamp, span)
```
@goodspark goodspark force-pushed the goodspark/add-within-times-assertion branch from 75d09c7 to 688c4ca Compare November 16, 2018 20:20
@goodspark goodspark changed the title Add a WithinTimes assertion Add a WithinTimes assertion Nov 16, 2018
@goodspark
Copy link
Author

I have no idea how to get go generate working. I'm on go 1.11.1 and the go generate ./... command yields the same problems as https://travis-ci.org/stretchr/testify/jobs/456142014#L477

@goodspark goodspark closed this by deleting the head repository Dec 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants