genofire/hs_monolith
genofire
/
hs_monolith
Archived
1
0
Fork 0
This repository has been archived on 2020-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
hs_monolith/models/good_release_test.go

42 lines
1022 B
Go

package models
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/genofire/hs_master-kss-monolith/lib/database"
)
func TestGoodRelease(t *testing.T) {
assert := assert.New(t)
database.Open(database.Config{
Type: "sqlite3",
Logging: true,
Connection: ":memory:",
})
now := time.Now()
good := Good{
LockedAt: &now,
LockedSecret: "never used",
}
database.Write.Create(&good)
count := goodRelease(time.Duration(3) * time.Second)
assert.Equal(int64(0), count, "no locked in timeout")
older := now.Add(-time.Duration(10) * time.Minute)
good.LockedAt = &older
database.Write.Save(&good)
count = goodRelease(time.Duration(3) * time.Second)
assert.Equal(int64(1), count, "unlock after timeout")
grw := NewGoodReleaseWorker(GoodReleaseConfig{
Every: Duration{Duration: time.Duration(3) * time.Millisecond},
After: Duration{Duration: time.Duration(5) * time.Millisecond},
})
go grw.Start()
time.Sleep(time.Duration(15) * time.Millisecond)
grw.Close()
}