From 39320d775f5c0b80417e902142e089631576f51c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=90=D0=BD=D0=B0=D1=82=D0=BE=D0=BB=D0=B8=D0=B9=20=D0=A2?= =?UTF-8?q?=D1=83=D1=85=D1=82=D0=B0=D1=80=D0=BE=D0=B2?= Date: Sat, 29 Jul 2023 10:44:46 +0500 Subject: [PATCH] =?UTF-8?q?=D1=82=D0=B5=D1=81=D1=82=D1=8B=20=D0=BF=D1=80?= =?UTF-8?q?=D0=BE=D1=85=D0=BE=D0=B4=D1=8F=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- picture.go | 2 +- picture_test.go | 2 +- seadb.go | 11 ++++++----- seadb_test.go | 23 ++++++++++++++--------- 4 files changed, 22 insertions(+), 16 deletions(-) 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 записей") }