-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathinterval_chain_test.go
More file actions
46 lines (38 loc) · 1.45 KB
/
interval_chain_test.go
File metadata and controls
46 lines (38 loc) · 1.45 KB
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
42
43
44
45
46
package scheduler
import (
"context"
"testing"
"github.com/cybertec-postgresql/pg_timetable/internal/config"
"github.com/cybertec-postgresql/pg_timetable/internal/log"
"github.com/cybertec-postgresql/pg_timetable/internal/pgengine"
"github.com/pashagolub/pgxmock/v5"
"github.com/stretchr/testify/assert"
)
func TestIntervalChain(t *testing.T) {
mock, err := pgxmock.NewPool()
assert.NoError(t, err)
pge := pgengine.NewDB(mock, "scheduler_unit_test")
sch := New(pge, log.Init(config.LoggingOpts{LogLevel: "panic", LogDBLevel: "none"}))
ichain := IntervalChain{Interval: 42}
assert.True(t, ichain.IsListed([]IntervalChain{ichain}))
assert.False(t, ichain.IsListed([]IntervalChain{}))
assert.False(t, sch.isValid(ichain))
sch.intervalChains[ichain.ChainID] = ichain
assert.True(t, sch.isValid(ichain))
t.Run("Check reschedule if self destructive", func(*testing.T) {
mock.ExpectExec("INSERT INTO timetable\\.log").WillReturnResult(pgxmock.NewResult("EXECUTE", 1))
mock.ExpectExec("DELETE").WillReturnResult(pgxmock.NewResult("EXECUTE", 1))
ichain.SelfDestruct = true
sch.reschedule(context.Background(), ichain)
})
t.Run("Check reschedule if context cancelled", func(*testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()
ichain.SelfDestruct = false
sch.reschedule(ctx, ichain)
})
t.Run("Check reschedule if everything fine", func(*testing.T) {
ichain.Interval = 1
sch.reschedule(context.Background(), ichain)
})
}