Skip to content

Commit 2dde7af

Browse files
author
Vladimir Smirnov
authored
Merge pull request #5 from SmilingNavern/feature/add-tests
Add basic test setup for sqlite
2 parents 5f50b35 + bd0c2dc commit 2dde7af

1 file changed

Lines changed: 66 additions & 0 deletions

File tree

db/sqlite_test.go

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

0 commit comments

Comments
 (0)