Video transformation unit test

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

@ -894,6 +894,10 @@ func transformVideo(source string, fullsizeDestination string, thumbnailDestinat
playbuttonAssetPath := filepath.Join(config.assets.assetsDir, config.assets.playIcon)
playbuttonOverlayBuffer, err := assets.ReadFile(playbuttonAssetPath)
if err != nil {
log.Println("Could not read play button overlay asset")
return err
}
playbuttonOverlayImage, err := vips.NewImageFromBuffer(playbuttonOverlayBuffer)
if err != nil {
log.Println("Could not open play button overlay asset")

@ -40,13 +40,17 @@ func TestE2E(t *testing.T) {
vips.Startup(nil)
createDirectory(gallery.absPath, false, config.files.directoryMode)
updateMediaFiles(0, source, gallery, false, false, config, nil)
updateMediaFiles(0, source, gallery, false, true, 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)
fullsizeFilename2 := filepath.Join(tempDir, "gallery", config.files.fullsizeDir, "dog.heic")
fullsizeFilename2 = stripExtension(fullsizeFilename2) + config.files.imageExtension
assert.FileExists(t, fullsizeFilename2)
thumbnailFilename1 := filepath.Join(tempDir, "gallery", "subdir", config.files.thumbnailDir, "gate.heic")
thumbnailFilename1 = stripExtension(thumbnailFilename1) + config.files.imageExtension
assert.FileExists(t, thumbnailFilename1)
@ -74,4 +78,12 @@ func TestE2E(t *testing.T) {
assert.EqualValues(t, 2, sourceChanges)
galleryChanges = countChanges(gallery, config)
assert.EqualValues(t, 3, galleryChanges)
// update without cleanup in gallery
updateMediaFiles(0, source, gallery, false, true, config, nil)
assert.FileExists(t, fullsizeFilename2)
// cleanup gallery
cleanUp(gallery, false, config)
assert.NoFileExists(t, fullsizeFilename2)
}

@ -4,6 +4,8 @@ import (
_ "io"
_ "log"
"os"
"os/exec"
"path/filepath"
"testing"
"time"
@ -14,7 +16,6 @@ var exitCount = 0
func testExit(ret int) {
exitCount = exitCount + 1
return
}
func TestValidateSourceAndGallery(t *testing.T) {
originalExit := exit
@ -341,6 +342,64 @@ func TestCreateDirectoryTree(t *testing.T) {
assert.EqualValues(t, 2, changes)
}
func TestTransformFileAndVideo(t *testing.T) {
const videoName = "video.mp4"
config := initializeConfig()
tempDir, err := os.MkdirTemp("", "fastgallery-test-")
if err != nil {
t.Error("couldn't create temporary directory")
}
defer os.RemoveAll(tempDir)
err = os.Mkdir(filepath.Join(tempDir, "source"), 0755)
assert.NoError(t, err)
err = os.Mkdir(filepath.Join(tempDir, "gallery"), 0755)
assert.NoError(t, err)
err = os.Mkdir(filepath.Join(tempDir, "gallery", config.files.fullsizeDir), 0755)
assert.NoError(t, err)
err = os.Mkdir(filepath.Join(tempDir, "gallery", config.files.thumbnailDir), 0755)
assert.NoError(t, err)
err = os.Mkdir(filepath.Join(tempDir, "gallery", config.files.originalDir), 0755)
assert.NoError(t, err)
cpCommand := exec.Command("cp", "-r", "../../testing/source/"+videoName, 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())
}
thumbnailFilename, fullsizeFilename := getGalleryFilenames(videoName, config)
testJob := transformationJob{
filename: videoName,
sourceFilepath: filepath.Join(tempDir, "source", videoName),
thumbnailFilepath: filepath.Join(tempDir, "gallery", config.files.thumbnailDir, thumbnailFilename),
fullsizeFilepath: filepath.Join(tempDir, "gallery", config.files.fullsizeDir, fullsizeFilename),
originalFilepath: filepath.Join(tempDir, "gallery", config.files.originalDir, videoName),
}
transformFile(testJob, nil, config)
assert.FileExists(t, testJob.thumbnailFilepath)
assert.FileExists(t, testJob.fullsizeFilepath)
err = os.RemoveAll(testJob.thumbnailFilepath)
assert.NoError(t, err)
os.RemoveAll(testJob.fullsizeFilepath)
assert.NoError(t, err)
transformVideo(testJob.sourceFilepath, testJob.fullsizeFilepath, testJob.thumbnailFilepath, config)
assert.FileExists(t, testJob.thumbnailFilepath)
assert.FileExists(t, testJob.fullsizeFilepath)
err = createOriginal(testJob.sourceFilepath, testJob.originalFilepath)
assert.NoError(t, err)
assert.FileExists(t, testJob.originalFilepath)
}
// TODO tests for
// isDirectory with symlinked dir
// isSymlinkDir

@ -1,26 +0,0 @@
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.1-0.20210222223032-a2b44e929db8
github.com/davidbyttow/govips/v2 v2.5.1-0.20210310125832-d6697b9d4676
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
@ -13,7 +13,7 @@ require (
github.com/stretchr/testify v1.6.1
golang.org/x/image v0.0.0-20210220032944-ac19c3e999fb // indirect
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
golang.org/x/sys v0.0.0-20210227040730-b0d1d43c014d // indirect
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2 // indirect
golang.org/x/text v0.3.5 // indirect
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776 // indirect
)

@ -14,6 +14,8 @@ github.com/davidbyttow/govips/v2 v2.5.0 h1:CLSVkXwZYfF7bOR5bZwlUFL1TIWXwyuNF33Ur
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/davidbyttow/govips/v2 v2.5.1-0.20210310125832-d6697b9d4676 h1:biB+3mY3qw1bfi8qKpD+FxGqbDgKJcyHXvq6TW1TWFY=
github.com/davidbyttow/govips/v2 v2.5.1-0.20210310125832-d6697b9d4676/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=
@ -59,6 +61,8 @@ golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210227040730-b0d1d43c014d h1:9fH9JvLNoSpsDWcXJ4dSE3lZW99Z3OCUZLr07g60U6o=
golang.org/x/sys v0.0.0-20210227040730-b0d1d43c014d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2 h1:46ULzRKLh1CwgRq2dC5SlBzEqqNCi8rreOZnNrbqcIY=
golang.org/x/sys v0.0.0-20210309074719-68d13333faf2/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=

Loading…
Cancel
Save