ssh-chat/internal/humantime/humantime_test.go
Robert Hailey 40bf204058 chat: When a user leaves, add time since they joined to the exit message.
* Show the connection duration upon departure

* humantime: ugly sub-second precision replaces grammatically incorrect "1 seconds" message

* simplify function name

* humantime: repair unit test

* move: util/humantime -> internal/humantime

* go fmt everything
2019-01-02 15:46:21 -05:00

42 lines
604 B
Go

package humantime
import (
"testing"
"time"
)
func TestHumanSince(t *testing.T) {
tests := []struct {
input time.Duration
expected string
}{
{
time.Second * 42,
"42 seconds",
},
{
time.Second * 60 * 5,
"5 minutes",
},
{
time.Hour * 3,
"3 hours",
},
{
time.Hour * 49,
"2 days",
},
{
time.Hour * 24 * 900,
"900 days",
},
}
for _, test := range tests {
absolute := time.Now().Add(test.input * -1)
if actual, expected := Since(absolute), test.expected; actual != expected {
t.Errorf("Got: %q; Expected: %q", actual, expected)
}
}
}