add tests

This commit is contained in:
lyx0 2021-10-28 23:20:48 +02:00
parent 8ddd54fc8c
commit 6b5a0ec6ac
2 changed files with 69 additions and 0 deletions

30
pkg/humanize/time_test.go Normal file
View 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
View 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
}