Skip to content

Commit 07c75b4

Browse files
committed
Add basic test setup for sqlite
1 parent 5f50b35 commit 07c75b4

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

db/sqlite_test.go

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package db
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"testing"
7+
"time"
8+
9+
"github.com/Civil/github2telegram/configs"
10+
_ "github.com/mattn/go-sqlite3"
11+
"github.com/stretchr/testify/suite"
12+
)
13+
14+
const (
15+
testDbName = "testgithub2telegram.dbdata"
16+
)
17+
18+
type SQLiteSuite struct {
19+
suite.Suite
20+
db Database
21+
}
22+
23+
func (s *SQLiteSuite) SetupSuite() {
24+
configs.Config.DatabaseURL = fmt.Sprintf("./%s", testDbName)
25+
s.db = NewSQLite()
26+
}
27+
28+
func (s *SQLiteSuite) TearDownSuite() {
29+
os.Remove(testDbName)
30+
}
31+
32+
func (s *SQLiteSuite) TestUpdateLastUpdateTime() {
33+
//url, filter, tag string, t time.Time
34+
t := time.Date(2018, time.June, 12, 7, 8, 0, 0, time.UTC)
35+
url := "https://test.com/test1"
36+
filter := ""
37+
version := "0.1.1"
38+
s.db.UpdateLastUpdateTime(url, filter, version, t)
39+
40+
tnew := s.db.GetLastUpdateTime(url, filter)
41+
42+
r := s.Require()
43+
r.Equal(t, tnew)
44+
}
45+
46+
func (s *SQLiteSuite) TestUpdateLastTag() {
47+
//url, filter, tag string, t time.Time
48+
t := time.Date(2018, time.June, 12, 7, 8, 0, 0, time.UTC)
49+
url := "https://bla.com/test2"
50+
filter := ""
51+
version := "0.2.3"
52+
s.db.UpdateLastUpdateTime(url, filter, version, t)
53+
54+
versionnew := s.db.GetLastTag(url, filter)
55+
56+
r := s.Require()
57+
r.Equal(version, versionnew)
58+
}
59+
60+
func TestDBSuite(t *testing.T) {
61+
ts := &SQLiteSuite{}
62+
suite.Run(t, ts)
63+
}

0 commit comments

Comments
 (0)