summaryrefslogtreecommitdiff
path: root/internal/utils/check_test.go
blob: 4545c2567082c392927588f4900ba5aaa2501cba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package utils

import (
	"errors"
	"testing"
	"time"

	"github.com/stretchr/testify/assert"
)

func TestCheckUntilPredicateOk(t *testing.T) {
	interval := time.Second * 1
	timeout := time.Second * 5

	err := CheckUntil(interval, timeout, func() (bool, error) {
		return true, nil
	})
	assert.NoError(t, err, "")
}

func TestCheckUntilPredicateError(t *testing.T) {
	interval := time.Second * 1
	timeout := time.Second * 5

	theError := errors.New("some error")

	err := CheckUntil(interval, timeout, func() (bool, error) {
		return false, theError
	})
	assert.ErrorIs(t, err, theError)
}

func TestCheckUntilPredicateTimeout(t *testing.T) {
	interval := 1 * time.Second
	timeout := 3 * time.Second

	err := CheckUntil(interval, timeout, func() (bool, error) {
		return false, nil
	})
	assert.ErrorContains(t, err, "timeout of 3s reached")
}