diff --git a/picture.go b/picture.go index 68ac63a..52addc8 100644 --- a/picture.go +++ b/picture.go @@ -3,7 +3,7 @@ package pic import ( "fmt" "strings" - "github.com/jmoiron/sqlx" + //"github.com/jmoiron/sqlx" ) //Picture - работа с картинками diff --git a/picture_test.go b/picture_test.go index bbd9ea6..6703383 100644 --- a/picture_test.go +++ b/picture_test.go @@ -8,7 +8,7 @@ import ( func TestNewPicture(t *testing.T) { // для тестирования базу данных не учитываем - p := NewPicture(nil, "проверка") + p := NewPicture("проверка") assert.Equal(t, p.Album, "проверка", "должны быть одинаковыми") } diff --git a/seadb.go b/seadb.go index 4d4c31c..305d96d 100644 --- a/seadb.go +++ b/seadb.go @@ -1,6 +1,7 @@ package pic import ( + "github.com/jmoiron/sqlx" ) //SeaDB - картинки в БД @@ -8,13 +9,13 @@ type SeaDB struct { db *sqlx.DB } -func NewSeaDB(db *qlx.DB) (*SeaDB, error) { +func NewSeaDB(db *sqlx.DB) (*SeaDB, error) { seadb := SeaDB{db: db} - return seadb + return &seadb, nil } //Возвращает список url-ов маленьких gif-ов их БД -func (sea *SeaDB)SmallGifs() ([]string, error) {} +func (sea *SeaDB)SmallGifs() ([]string, error) { cmd := ` SELECT newurl @@ -25,8 +26,8 @@ func (sea *SeaDB)SmallGifs() ([]string, error) {} WHERE ext = '.gif' and del = 0 - and a.converted = 0 - and b.width < 400 + and filemeta.converted = 0 + and pic.width < 400 LIMIT 10; ` diff --git a/seadb_test.go b/seadb_test.go index 96b7d8c..aadf3e0 100644 --- a/seadb_test.go +++ b/seadb_test.go @@ -4,19 +4,24 @@ import ( //"log" "testing" "github.com/stretchr/testify/assert" + "github.com/jmoiron/sqlx" ) -func TestGetSmallGifs(t *testing.T) { - url, err := upload("weed_test.go") - assert.Nil(t, err) - //log.Printf("url: %s\n", url) +var db = openDB() +func openDB() *sqlx.DB { + db, err := sqlx.Open("mysql", "itman:X753951x@(xigmanas:3306)/sea") + if err != nil { + panic(err) + } + return db +} - // проверка на обработку ошибок (перепутал url и fid) - err = delete("4,23456") - assert.NotNil(t, err) +func TestGetSmallGifs(t *testing.T) { + seadb, err := NewSeaDB(db) + assert.Nil(t, err) - // проверка на корректный url - err = delete(url) + urls, err := seadb.SmallGifs() assert.Nil(t, err) + assert.Equal(t, len(urls), 10, "должны получить 10 записей") }