diff --git a/.gitignore b/.gitignore index 3b735ec..ad6f2c5 100644 --- a/.gitignore +++ b/.gitignore @@ -19,3 +19,4 @@ # Go workspace file go.work +/test diff --git a/go.mod b/go.mod index a8e1c4f..5689f94 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,5 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/stretchr/objx v0.5.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/picture_test.go b/picture_test.go index 6703383..5e2191b 100644 --- a/picture_test.go +++ b/picture_test.go @@ -3,6 +3,7 @@ package pic import ( //"log" "testing" + "github.com/stretchr/testify/assert" ) @@ -12,7 +13,7 @@ func TestNewPicture(t *testing.T) { assert.Equal(t, p.Album, "проверка", "должны быть одинаковыми") } -func TestbaseName(t *testing.T) { +func TestBaseName(t *testing.T) { base := baseName("c:\\Проверка файла с каталогом\\test.jpg") assert.Equal(t, base, "test", "должны быть одинаковыми") @@ -27,4 +28,4 @@ func TestbaseName(t *testing.T) { base = baseName("test.jpg") assert.NotEqual(t, base, "неверное имя", "должны быть разными") -} \ No newline at end of file +} diff --git a/seadb_test.go b/seadb_test.go index 4d79b09..fe2406b 100644 --- a/seadb_test.go +++ b/seadb_test.go @@ -53,3 +53,25 @@ func TestGetSmallGifs(t *testing.T) { err = download(url, filepath.Join("test", filename)) assert.Nil(t, err) } + +func BenchmarkDownload(b *testing.B) { + seadb, err := NewSeaDB(db) + if err != nil { + panic(err) + } + urls, err := seadb.SmallGifs() + if err != nil { + panic(err) + } + + for _, url := range urls { + filename, err := getFilename(url) + if err != nil { + panic(err) + } + err = download(url, filepath.Join("test", filename)) + if err != nil { + panic(err) + } + } +} diff --git a/test/23441c89622148.gif b/test/23441c89622148.gif deleted file mode 100644 index 8714d0e..0000000 Binary files a/test/23441c89622148.gif and /dev/null differ diff --git a/weed.go b/weed.go index 61b6d72..4b4e5b2 100644 --- a/weed.go +++ b/weed.go @@ -3,7 +3,6 @@ package pic import ( "fmt" "io" - "io/ioutil" "net/http" "os" "strings" @@ -58,7 +57,7 @@ func download(url string, filename string) error { } _, err = sw.Download(fid, nil, func(r io.Reader) (err error) { - data, err := ioutil.ReadAll(r) + data, err := io.ReadAll(r) if err != nil { return err }