1
0
Fork 0

Test Store's LoadFromRecords method

main
Daniele Tricoli 7 years ago
parent 005c285bf7
commit a1dd484d44
  1. 10
      sql/sql.go
  2. 18
      sql/sql_test.go

@ -52,6 +52,7 @@ const (
createLastUpdateQuery = `INSERT INTO last_update (filename, date) VALUES (?, ?)`
getLastUpdateQuery = `SELECT date FROM last_update WHERE filename = ?`
getUnicodeQuery = `SELECT codepoint, name, category FROM unicode_data WHERE name MATCH ?`
countUnicodeQuery = `SELECT count(*) FROM unicode_data`
)
type Store struct {
@ -192,3 +193,12 @@ func (s *Store) SearchUnicode(name string) (records []UnicodeData, err error) {
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
}

@ -108,5 +108,23 @@ func TestLastUpdate(t *testing.T) {
}
updateTime, err = store.GetLastUpdate("test.txt")
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)
}

Loading…
Cancel
Save