E2E testing

pull/7/head
Toni Melisma 3 years ago
parent e3bd069775
commit b6f722015d
No known key found for this signature in database
GPG Key ID: FFF9A7EDDEA34756

@ -965,14 +965,18 @@ func transformFile(thisJob transformationJob, progressBar *pb.ProgressBar, confi
err := transformImage(thisJob.sourceFilepath, thisJob.fullsizeFilepath, thisJob.thumbnailFilepath, config)
if err != nil {
cleanWipFiles(thisJob.sourceFilepath)
progressBar.Increment()
if progressBar != nil {
progressBar.Increment()
}
return
}
} else if isVideoFile(thisJob.filename) {
err := transformVideo(thisJob.sourceFilepath, thisJob.fullsizeFilepath, thisJob.thumbnailFilepath, config)
if err != nil {
cleanWipFiles(thisJob.sourceFilepath)
progressBar.Increment()
if progressBar != nil {
progressBar.Increment()
}
return
}
} else {
@ -982,10 +986,14 @@ func transformFile(thisJob transformationJob, progressBar *pb.ProgressBar, confi
err := createOriginal(thisJob.sourceFilepath, thisJob.originalFilepath)
if err != nil {
cleanWipFiles(thisJob.sourceFilepath)
progressBar.Increment()
if progressBar != nil {
progressBar.Increment()
}
return
}
progressBar.Increment()
if progressBar != nil {
progressBar.Increment()
}
wipJobMutex.Lock()
delete(wipJobs, thisJob.sourceFilepath)

@ -0,0 +1,77 @@
package main
import (
"os"
"os/exec"
"path/filepath"
"testing"
"time"
"github.com/davidbyttow/govips/v2/vips"
"github.com/stretchr/testify/assert"
)
func TestE2E(t *testing.T) {
tempDir, err := os.MkdirTemp("", "fastgallery-test-")
if err != nil {
t.Error("couldn't create temporary directory")
}
defer os.RemoveAll(tempDir)
cpCommand := exec.Command("cp", "-r", "../../testing/source", filepath.Join(tempDir, "source"))
cpCommandOutput, err := cpCommand.CombinedOutput()
if len(cpCommandOutput) > 0 {
t.Error("cp produced output", string(cpCommandOutput))
}
assert.NoError(t, err)
config := initializeConfig()
source := createDirectoryTree(filepath.Join(tempDir, "source"), "", true)
gallery := createDirectoryTree(filepath.Join(tempDir, "gallery"), "", true)
compareDirectoryTrees(&source, &gallery, config)
sourceChanges := countChanges(source, config)
assert.EqualValues(t, 9, sourceChanges)
galleryChanges := countChanges(gallery, config)
assert.EqualValues(t, 0, galleryChanges)
vips.LoggingSettings(nil, vips.LogLevelWarning)
//log.SetOutput(io.Discard)
vips.Startup(nil)
createDirectory(gallery.absPath, false, config.files.directoryMode)
updateMediaFiles(0, source, gallery, false, false, config, nil)
// Gallery created, test that files are in order
fullsizeFilename1 := filepath.Join(tempDir, "gallery", config.files.fullsizeDir, "panorama.heic")
fullsizeFilename1 = stripExtension(fullsizeFilename1) + config.files.imageExtension
assert.FileExists(t, fullsizeFilename1)
thumbnailFilename1 := filepath.Join(tempDir, "gallery", "subdir", config.files.thumbnailDir, "gate.heic")
thumbnailFilename1 = stripExtension(thumbnailFilename1) + config.files.imageExtension
assert.FileExists(t, thumbnailFilename1)
originalFilename1 := filepath.Join(tempDir, "gallery", "subdir", "subsubdir", config.files.originalDir, "recorder.heic")
assert.FileExists(t, originalFilename1)
// Make changes and re-test
sourceFilename1 := filepath.Join(tempDir, "source", "street.jpg")
err = os.Chtimes(sourceFilename1, time.Now().Local(), time.Now().Local())
assert.NoError(t, err)
sourceFilename2 := filepath.Join(tempDir, "source", "cranes.jpg")
err = os.Chtimes(sourceFilename2, time.Now().Local(), time.Now().Local())
assert.NoError(t, err)
sourceFilename3 := filepath.Join(tempDir, "source", "dog.heic")
err = os.RemoveAll(sourceFilename3)
assert.NoError(t, err)
source = createDirectoryTree(filepath.Join(tempDir, "source"), "", true)
gallery = createDirectoryTree(filepath.Join(tempDir, "gallery"), "", true)
compareDirectoryTrees(&source, &gallery, config)
sourceChanges = countChanges(source, config)
assert.EqualValues(t, 2, sourceChanges)
galleryChanges = countChanges(gallery, config)
assert.EqualValues(t, 3, galleryChanges)
}

@ -1,6 +1,8 @@
package main
import (
_ "io"
_ "log"
"os"
"testing"
"time"

@ -0,0 +1,26 @@
package main
import (
"os"
"os/exec"
"path/filepath"
"testing"
)
func TestTransform(t *testing.T) {
tempDir, err := os.MkdirTemp("", "fastgallery-test-")
if err != nil {
t.Error("couldn't create temporary directory")
}
defer os.RemoveAll(tempDir)
cpCommand := exec.Command("cp", "-r", "../../testing/source", filepath.Join(tempDir, "source"))
cpCommandOutput, err := cpCommand.CombinedOutput()
if len(cpCommandOutput) > 0 {
t.Error("cp produced output", string(cpCommandOutput))
}
if err != nil {
t.Error("cp error", err.Error())
}
}

@ -5,7 +5,7 @@ go 1.16
require (
github.com/alexflint/go-arg v1.3.0
github.com/cheggaaa/pb/v3 v3.0.6
github.com/davidbyttow/govips/v2 v2.5.0
github.com/davidbyttow/govips/v2 v2.5.1-0.20210222223032-a2b44e929db8
github.com/fatih/color v1.10.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/mattn/go-runewidth v0.0.10 // indirect

@ -12,6 +12,8 @@ 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.5.0 h1:CLSVkXwZYfF7bOR5bZwlUFL1TIWXwyuNF33UrlKscM4=
github.com/davidbyttow/govips/v2 v2.5.0/go.mod h1:goq38QD8XEMz2aWEeucEZqRxAWsemIN40vbUqfPfTAw=
github.com/davidbyttow/govips/v2 v2.5.1-0.20210222223032-a2b44e929db8 h1:VqpZsVBlteJKrItEWLqqqUBgWwQFjQUHOAuREaVc+II=
github.com/davidbyttow/govips/v2 v2.5.1-0.20210222223032-a2b44e929db8/go.mod h1:goq38QD8XEMz2aWEeucEZqRxAWsemIN40vbUqfPfTAw=
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=

Before

Width:  |  Height:  |  Size: 2.2 MiB

After

Width:  |  Height:  |  Size: 2.2 MiB

Before

Width:  |  Height:  |  Size: 721 KiB

After

Width:  |  Height:  |  Size: 721 KiB

Before

Width:  |  Height:  |  Size: 3.0 MiB

After

Width:  |  Height:  |  Size: 3.0 MiB

Loading…
Cancel
Save