Skip to content

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 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