-
Notifications
You must be signed in to change notification settings - Fork 0
/
last_checked_dao_test.go
49 lines (40 loc) · 1.07 KB
/
last_checked_dao_test.go
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
47
48
49
package main
import (
"fmt"
"github.com/stretchr/testify/suite"
"os"
"testing"
"time"
)
type LastCheckedDaoSuite struct {
suite.Suite
filename string
dao LastCheckedDao
}
func TestLastCheckedDaoSuite(t *testing.T) {
suite.Run(t, new(LastCheckedDaoSuite))
}
func (s *LastCheckedDaoSuite) SetupSuite() {
s.filename = fmt.Sprintf("%s_%d.txt", "test_last_checked", time.Now().Unix())
s.dao = NewLastCheckedDao(Config{LastCheckedFile: s.filename})
}
func (s *LastCheckedDaoSuite) SetupTest() {
_ = os.Remove(s.filename)
}
func (s *LastCheckedDaoSuite) TearDownSuite() {
_ = os.Remove(s.filename)
}
func (s *LastCheckedDaoSuite) TestGetBeforeSet() {
_, isExist, err := s.dao.GetLastChecked()
s.Assert().False(isExist)
s.Assert().NoError(err)
}
func (s *LastCheckedDaoSuite) TestSetGet() {
expected, err := time.Parse(time.RFC3339, "2024-06-03T21:28:00Z")
s.Require().NoError(err)
s.Require().NoError(s.dao.SetLastChecked(expected))
actual, isExist, err := s.dao.GetLastChecked()
s.Assert().NoError(err)
s.Assert().True(isExist)
s.Assert().Equal(expected, actual)
}