1
0
Fork 0

Test Store's LoadFromRecords method

This commit is contained in:
Daniele Tricoli 2015-12-11 03:04:30 +01:00
parent 005c285bf7
commit a1dd484d44
2 changed files with 29 additions and 1 deletions

View File

@ -52,6 +52,7 @@ const (
createLastUpdateQuery = `INSERT INTO last_update (filename, date) VALUES (?, ?)` createLastUpdateQuery = `INSERT INTO last_update (filename, date) VALUES (?, ?)`
getLastUpdateQuery = `SELECT date FROM last_update WHERE filename = ?` getLastUpdateQuery = `SELECT date FROM last_update WHERE filename = ?`
getUnicodeQuery = `SELECT codepoint, name, category FROM unicode_data WHERE name MATCH ?` getUnicodeQuery = `SELECT codepoint, name, category FROM unicode_data WHERE name MATCH ?`
countUnicodeQuery = `SELECT count(*) FROM unicode_data`
) )
type Store struct { type Store struct {
@ -192,3 +193,12 @@ func (s *Store) SearchUnicode(name string) (records []UnicodeData, err error) {
return records, nil return records, nil
} }
// Count total rows inside unicode data table.
func (s *Store) CountUnicodeData() int {
var total int
s.db.QueryRow(countUnicodeQuery).Scan(&total)
return total
}

View File

@ -108,5 +108,23 @@ func TestLastUpdate(t *testing.T) {
} }
updateTime, err = store.GetLastUpdate("test.txt") updateTime, err = store.GetLastUpdate("test.txt")
assert.Equal(t, updateTime, testTime) assert.Equal(t, updateTime, testTime)
}
func TestLoadFromRecords(t *testing.T) {
dirName, err := store.init()
if err != nil {
assert.Error(t, err)
}
defer os.RemoveAll(dirName)
defer store.Close()
records := [][]string{
[]string{"1F60E", "SMILING FACE WITH SUNGLASSES", "So", "", "", "", "", "", "", "", "", "", "", "", ""},
[]string{"1F602", "FACE WITH TEARS OF JOY", "So", "", "", "", "", "", "", "", "", "", "", "", ""},
[]string{"1F4D7", "GREEN BOOK", "So", "", "", "", "", "", "", "", "", "", "", "", ""},
}
store.LoadFromRecords(records)
assert.Equal(t, store.CountUnicodeData(), 3)
} }