master
Andrey Ivanov 2020-12-10 05:02:17 -05:00 committed by Andrey Ivanov
parent 4824e1c110
commit c7941f595a
3 changed files with 10 additions and 5 deletions

View File

@ -19,4 +19,5 @@ linters:
- bodyclose
- wrapcheck
- exhaustivestruct
- staticcheck
- staticcheck
- gofumpt

View File

@ -113,7 +113,11 @@ func (s Interface) SetFromDB(db *sql.DB, dbname string) error {
defer db.Close()
res := make(map[string]string)
var key, val string
results, err := db.Query("SELECT key, value FROM ?", dbname)
//TODO: Перенести это в параметры.
table := "config"
q := "SELECT " + table + ".key, " + table + ".value FROM " + table
results, err := db.Query(q)
if err != nil || results.Err() != nil {
return fmt.Errorf("can't get key-value pairs from DB: %w", err)
}

View File

@ -242,7 +242,7 @@ func TestSetFromDBPositive(t *testing.T) {
rows.AddRow("SECTION2.VARSTRING2", "second string")
rows.AddRow("SECTION2.VARBOOL2", "true")
mock.ExpectQuery("SELECT key, value FROM").WithArgs("config").WillReturnRows(rows)
mock.ExpectQuery("SELECT config.key, config.value FROM config").WillReturnRows(rows)
var c TestConf
i := New(&c)
err := i.SetFromDB(db, "config")
@ -265,7 +265,7 @@ func TestSetFromDBPositive(t *testing.T) {
rows.AddRow("SECTION2.VARSTRING2", "second string")
rows.AddRow("SECTION2.VARBOOL2", "true")
mock.ExpectQuery("SELECT key, value FROM").WithArgs("config").WillReturnRows(rows)
mock.ExpectQuery("SELECT config.key, config.value FROM config").WillReturnRows(rows)
var c TestConf
i := New(&c)
err := i.SetFromDB(db, "config")
@ -285,7 +285,7 @@ func TestSetFromDBPositive(t *testing.T) {
rows := sqlmock.NewRows([]string{"key", "value"})
mock.ExpectQuery("SELECT key, value FROM").WithArgs("config").WillReturnRows(rows)
mock.ExpectQuery("SELECT config.key, config.value FROM config").WillReturnRows(rows)
var c TestConf
i := New(&c)
err := i.SetFromDB(db, "config")