Initialize rewrite

pull/3/head
Toni Melisma 3 years ago
parent 6f6bde43f1
commit 666f1893c3
No known key found for this signature in database
GPG Key ID: FFF9A7EDDEA34756

File diff suppressed because it is too large Load Diff

@ -1,44 +1,188 @@
package main
import (
"io/ioutil"
"os"
"testing"
"github.com/stretchr/testify/assert"
)
func TestIsVideoFile(t *testing.T) {
assert.Equal(t, isVideoFile("test.txt"), false, "false positive")
assert.Equal(t, isVideoFile(""), false, "false positive")
assert.Equal(t, isVideoFile("test.mp4"), true, "false negative")
assert.Equal(t, isVideoFile("test.mov"), true, "false negative")
assert.Equal(t, isVideoFile("test.3gp"), true, "false negative")
assert.Equal(t, isVideoFile("test.avi"), true, "false negative")
assert.Equal(t, isVideoFile("test.mts"), true, "false negative")
assert.Equal(t, isVideoFile("test.m4v"), true, "false negative")
assert.Equal(t, isVideoFile("test.mpg"), true, "false negative")
assert.Equal(t, isVideoFile("test.MP4"), true, "false negative")
}
func TestIsImageFile(t *testing.T) {
assert.Equal(t, isImageFile("test.txt"), false, "false positive")
assert.Equal(t, isImageFile(""), false, "false positive")
assert.Equal(t, isImageFile("test.jpg"), true, "false negative")
assert.Equal(t, isImageFile("test.JPG"), true, "false negative")
assert.Equal(t, isImageFile("test.jpeg"), true, "false negative")
assert.Equal(t, isImageFile("test.heic"), true, "false negative")
assert.Equal(t, isImageFile("test.png"), true, "false negative")
assert.Equal(t, isImageFile("test.tif"), true, "false negative")
assert.Equal(t, isImageFile("test.tiff"), true, "false negative")
}
func TestIsMediaFile(t *testing.T) {
assert.Equal(t, isMediaFile("test.txt"), false, "false positive")
assert.Equal(t, isMediaFile("test.jpg"), true, "false negative")
assert.Equal(t, isMediaFile("test.mp4"), true, "false negative")
}
func TestStripExtension(t *testing.T) {
assert.Equal(t, stripExtension("../tmp/filename.txt"), "../tmp/filename", "mismatch")
assert.Equal(t, stripExtension("/tmp/filename.txt"), "/tmp/filename", "mismatch")
assert.Equal(t, stripExtension("filename.txt"), "filename", "mismatch")
var exitCount = 0
func testExit(ret int) {
exitCount = exitCount + 1
return
}
func TestValidateSourceAndGallery(t *testing.T) {
originalExit := exit
defer func() { exit = originalExit }()
exit = testExit
tempDir, err := ioutil.TempDir("", "fastgallery-test-")
if err != nil {
t.Error("couldn't create temporary directory")
}
defer os.RemoveAll(tempDir)
exitCountBefore := exitCount
_, _ = validateSourceAndGallery(tempDir+"/nonexistent", tempDir+"/gallery")
assert.EqualValues(t, exitCountBefore+1, exitCount, "validateArgs did not exit")
exitCountBefore = exitCount
_, _ = validateSourceAndGallery(tempDir, tempDir+"/gallery/nonexistent")
assert.EqualValues(t, exitCountBefore+1, exitCount, "validateArgs did not exit")
exitCountBefore = exitCount
_, _ = validateSourceAndGallery(tempDir, tempDir+"/gallery")
assert.EqualValues(t, exitCountBefore, exitCount, "validateArgs did not exit")
}
func TestIsDirectory(t *testing.T) {
tempDir, err := ioutil.TempDir("", "fastgallery-test-")
if err != nil {
t.Error("couldn't create temporary directory")
}
defer os.RemoveAll(tempDir)
err = os.Mkdir(tempDir+"/subdir", 0755)
if err != nil {
t.Error("couldn't create subdirectory")
}
defer os.RemoveAll(tempDir + "/subdir")
assert.True(t, isDirectory(tempDir+"/subdir"))
err = os.Symlink(tempDir+"/subdir", tempDir+"/symlink")
if err != nil {
t.Error("couldn't create symlink")
}
defer os.RemoveAll(tempDir + "/symlink")
assert.True(t, isDirectory(tempDir+"/symlink"))
emptyFile, err := os.Create(tempDir + "/file")
if err != nil {
t.Error("couldn't create symlink")
}
defer emptyFile.Close()
defer os.RemoveAll(tempDir + "/file")
assert.False(t, isDirectory(tempDir+"/file"))
assert.False(t, isDirectory(tempDir+"/nonexistent"))
}
func TestExists(t *testing.T) {
tempDir, err := ioutil.TempDir("", "fastgallery-test-")
if err != nil {
t.Error("couldn't create temporary directory")
}
defer os.RemoveAll(tempDir)
emptyFile, err := os.Create(tempDir + "/file")
if err != nil {
t.Error("couldn't create symlink")
}
defer emptyFile.Close()
defer os.RemoveAll(tempDir + "/file")
assert.True(t, exists(tempDir+"/file"))
assert.False(t, exists(tempDir+"/nonexistent"))
}
func TestDirHasMediaFiles(t *testing.T) {
tempDir, err := ioutil.TempDir("", "fastgallery-test-")
if err != nil {
t.Error("couldn't create temporary directory")
}
defer os.RemoveAll(tempDir)
emptyFile, err := os.Create(tempDir + "/file.jpg")
if err != nil {
t.Error("couldn't create symlink")
}
defer emptyFile.Close()
defer os.RemoveAll(tempDir + "/file.jpg")
assert.True(t, dirHasMediafiles(tempDir))
}
func TestDirHasMediaFilesFailing(t *testing.T) {
tempDir, err := ioutil.TempDir("", "fastgallery-test-")
if err != nil {
t.Error("couldn't create temporary directory")
}
defer os.RemoveAll(tempDir)
emptyFile, err := os.Create(tempDir + "/file.txt")
if err != nil {
t.Error("couldn't create symlink")
}
defer emptyFile.Close()
defer os.RemoveAll(tempDir + "/file.txt")
assert.False(t, dirHasMediafiles(tempDir))
}
func TestDirHasMediaFilesRecurse(t *testing.T) {
tempDir, err := ioutil.TempDir("", "fastgallery-test-")
if err != nil {
t.Error("couldn't create temporary directory")
}
defer os.RemoveAll(tempDir)
err = os.Mkdir(tempDir+"/subdir", 0755)
if err != nil {
t.Error("couldn't create subdirectory")
}
defer os.RemoveAll(tempDir + "/subdir")
emptyFile, err := os.Create(tempDir + "/subdir/file.jpg")
if err != nil {
t.Error("couldn't create symlink")
}
defer emptyFile.Close()
defer os.RemoveAll(tempDir + "/subdir/file.jpg")
assert.True(t, dirHasMediafiles(tempDir))
}
func TestDirHasMediaFilesRecurseFailing(t *testing.T) {
tempDir, err := ioutil.TempDir("", "fastgallery-test-")
if err != nil {
t.Error("couldn't create temporary directory")
}
defer os.RemoveAll(tempDir)
err = os.Mkdir(tempDir+"/subdir", 0755)
if err != nil {
t.Error("couldn't create subdirectory")
}
defer os.RemoveAll(tempDir + "/subdir")
emptyFile, err := os.Create(tempDir + "/subdir/file.txt")
if err != nil {
t.Error("couldn't create symlink")
}
defer emptyFile.Close()
defer os.RemoveAll(tempDir + "/subdir/file.txt")
assert.False(t, dirHasMediafiles(tempDir))
}
func TestIsXxxFile(t *testing.T) {
assert.True(t, isVideoFile("test.mp4"))
assert.False(t, isVideoFile("test.jpg"))
assert.False(t, isVideoFile("test.txt"))
assert.True(t, isImageFile("test.jpg"))
assert.False(t, isImageFile("test.mp4"))
assert.False(t, isImageFile("test.txt"))
assert.True(t, isMediaFile("test.mp4"))
assert.True(t, isMediaFile("test.jpg"))
assert.False(t, isMediaFile("test.txt"))
}
// TODO tests for
// createDirectoryTree
// stripExtension
// compareDirectoryTrees
// - exists, doesn't exist, some gallery files exist / some don't
// - thumbnail modified earlier than original or vice versa

File diff suppressed because it is too large Load Diff

@ -0,0 +1,44 @@
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestIsVideoFile(t *testing.T) {
assert.Equal(t, isVideoFile("test.txt"), false, "false positive")
assert.Equal(t, isVideoFile(""), false, "false positive")
assert.Equal(t, isVideoFile("test.mp4"), true, "false negative")
assert.Equal(t, isVideoFile("test.mov"), true, "false negative")
assert.Equal(t, isVideoFile("test.3gp"), true, "false negative")
assert.Equal(t, isVideoFile("test.avi"), true, "false negative")
assert.Equal(t, isVideoFile("test.mts"), true, "false negative")
assert.Equal(t, isVideoFile("test.m4v"), true, "false negative")
assert.Equal(t, isVideoFile("test.mpg"), true, "false negative")
assert.Equal(t, isVideoFile("test.MP4"), true, "false negative")
}
func TestIsImageFile(t *testing.T) {
assert.Equal(t, isImageFile("test.txt"), false, "false positive")
assert.Equal(t, isImageFile(""), false, "false positive")
assert.Equal(t, isImageFile("test.jpg"), true, "false negative")
assert.Equal(t, isImageFile("test.JPG"), true, "false negative")
assert.Equal(t, isImageFile("test.jpeg"), true, "false negative")
assert.Equal(t, isImageFile("test.heic"), true, "false negative")
assert.Equal(t, isImageFile("test.png"), true, "false negative")
assert.Equal(t, isImageFile("test.tif"), true, "false negative")
assert.Equal(t, isImageFile("test.tiff"), true, "false negative")
}
func TestIsMediaFile(t *testing.T) {
assert.Equal(t, isMediaFile("test.txt"), false, "false positive")
assert.Equal(t, isMediaFile("test.jpg"), true, "false negative")
assert.Equal(t, isMediaFile("test.mp4"), true, "false negative")
}
func TestStripExtension(t *testing.T) {
assert.Equal(t, stripExtension("../tmp/filename.txt"), "../tmp/filename", "mismatch")
assert.Equal(t, stripExtension("/tmp/filename.txt"), "/tmp/filename", "mismatch")
assert.Equal(t, stripExtension("filename.txt"), "filename", "mismatch")
}

@ -1,14 +1,9 @@
module github.com/tonimelisma/fastgallery
module fastgallery-rewrite
go 1.15
require (
github.com/cheggaaa/pb/v3 v3.0.5
github.com/davidbyttow/govips/v2 v2.2.0
github.com/fatih/color v1.10.0 // indirect
github.com/mattn/go-runewidth v0.0.9 // indirect
github.com/alexflint/go-arg v1.3.0
github.com/kr/pretty v0.2.1
github.com/stretchr/testify v1.6.1
golang.org/x/image v0.0.0-20201208152932-35266b937fa6 // indirect
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11 // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
)

@ -1,67 +1,23 @@
github.com/VividCortex/ewma v1.1.1 h1:MnEK4VOv6n0RSY4vtRe3h11qjxL3+t0B8yOL8iMXdcM=
github.com/VividCortex/ewma v1.1.1/go.mod h1:2Tkkvm3sRDVXaiyucHiACn4cqf7DpdyLvmxzcbUokwA=
github.com/cheggaaa/pb/v3 v3.0.5 h1:lmZOti7CraK9RSjzExsY53+WWfub9Qv13B5m4ptEoPE=
github.com/cheggaaa/pb/v3 v3.0.5/go.mod h1:X1L61/+36nz9bjIsrDU52qHKOQukUQe2Ge+YvGuquCw=
github.com/alexflint/go-arg v1.3.0 h1:UfldqSdFWeLtoOuVRosqofU4nmhI1pYEbT4ZFS34Bdo=
github.com/alexflint/go-arg v1.3.0/go.mod h1:9iRbDxne7LcR/GSvEr7ma++GLpdIU1zrghf2y2768kM=
github.com/alexflint/go-scalar v1.0.0 h1:NGupf1XV/Xb04wXskDFzS0KWOLH632W/EO4fAFi+A70=
github.com/alexflint/go-scalar v1.0.0/go.mod h1:GpHzbCOZXEKMEcygYQ5n/aa4Aq84zbxjy3MxYW0gjYw=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davidbyttow/govips/v2 v2.2.0 h1:O21ykVQNJ7LYxpa7yG6TN2g2VF/WonOksljCD2jQK4o=
github.com/davidbyttow/govips/v2 v2.2.0/go.mod h1:goq38QD8XEMz2aWEeucEZqRxAWsemIN40vbUqfPfTAw=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fatih/color v1.10.0 h1:s36xzo75JdqLaaWoiEHk767eHiwo0598uUxyfiPkDsg=
github.com/fatih/color v1.10.0/go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM=
github.com/kr/pretty v0.2.1 h1:Fmg33tUaq4/8ym9TJN1x7sLJnHVwhP33CNkpYV/7rwI=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8=
github.com/mattn/go-colorable v0.1.8/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-runewidth v0.0.7 h1:Ei8KR0497xHyKJPAv59M1dkC+rOZCMBJ+t3fZ+twI54=
github.com/mattn/go-runewidth v0.0.7/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs=
github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5 h1:QelT11PB4FXiDEXucrfNckHoFxwt8USGY1ajP1ZF5lM=
golang.org/x/image v0.0.0-20200927104501-e162460cd6b5/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/image v0.0.0-20201208152932-35266b937fa6 h1:nfeHNc1nAqecKCy2FCy4HY+soOOe5sDLJ/gZLbx6GYI=
golang.org/x/image v0.0.0-20201208152932-35266b937fa6/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102 h1:42cLlJJdEh+ySyeUUbEQ5bsTiq8voBeTuweGVkY6Puw=
golang.org/x/net v0.0.0-20201031054903-ff519b6c9102/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11 h1:lwlPPsmjDKK0J6eG6xDWd5XPehI0R024zxjDnw3esPA=
golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42 h1:vEOn+mP2zCOVzKckCZy6YsCtDblrpj/w7B9nxGNELpg=
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68 h1:nxC68pudNYkKU6jWhgrqdreuFiOQWj1Fs7T3VrH4Pjw=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.4 h1:0YWbFKbhXG/wIiuHDSKpS0Iy7FSA+u45VtBMfQcFTTc=
golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b h1:QRR6H1YWRnHb4Y/HeNFCTJLFVxaq6wH4YuVdsUOr75U=
gopkg.in/check.v1 v1.0.0-20200902074654-038fdea0a05b/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 h1:tQIYjPdBoyREyB9XMu+nnTclpTYkz2zFM+lzLJFO4gQ=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=

Loading…
Cancel
Save