mirror of
https://github.com/lyx0/nourybot.git
synced 2024-11-13 19:49:55 +01:00
add tests
This commit is contained in:
parent
8ddd54fc8c
commit
6b5a0ec6ac
30
pkg/humanize/time_test.go
Normal file
30
pkg/humanize/time_test.go
Normal file
|
@ -0,0 +1,30 @@
|
|||
package humanize
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
func TestTime(t *testing.T) {
|
||||
t.Run("tests the humanized time", func(t *testing.T) {
|
||||
|
||||
now := time.Now()
|
||||
|
||||
fmt.Println("now:", now)
|
||||
|
||||
count := 10
|
||||
// then is the current time - 10 minutes.
|
||||
then := now.Add(time.Duration(-count) * time.Minute)
|
||||
|
||||
request := Time(then)
|
||||
response := "10 minutes ago"
|
||||
|
||||
got := request
|
||||
want := response
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got %v, want %v", got, want)
|
||||
}
|
||||
})
|
||||
}
|
39
pkg/utils/utils_test.go
Normal file
39
pkg/utils/utils_test.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"testing"
|
||||
)
|
||||
|
||||
// I don't know how to test the other ones since they are random
|
||||
func TestCommandsUsed(t *testing.T) {
|
||||
t.Run("tests the commands used counter", func(t *testing.T) {
|
||||
|
||||
request := mockCommandsUsed(127)
|
||||
response := 127
|
||||
|
||||
got := request
|
||||
want := response
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got %v, want %v", got, want)
|
||||
}
|
||||
|
||||
// 127 + 53
|
||||
request = mockCommandsUsed(53)
|
||||
response = 180
|
||||
|
||||
got = request
|
||||
want = response
|
||||
|
||||
if got != want {
|
||||
t.Errorf("got %v, want %v", got, want)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
func mockCommandsUsed(n int) int {
|
||||
for i := 0; i < n; i++ {
|
||||
CommandUsed()
|
||||
}
|
||||
return tempCommands
|
||||
}
|
Loading…
Reference in a new issue