mirror of
https://github.com/photoprism/photoprism.git
synced 2026-01-23 02:24:24 +00:00
Fix slow tests and improve test output (colorized) #58
This commit is contained in:
parent
fb91ce9a06
commit
f7404f838b
16 changed files with 34 additions and 15 deletions
6
Makefile
6
Makefile
|
|
@ -27,11 +27,11 @@ start:
|
|||
migrate:
|
||||
go run cmd/photoprism/photoprism.go migrate
|
||||
test:
|
||||
go test -tags=slow -timeout 20m -v ./internal/...
|
||||
go test -tags=slow -timeout 20m -v ./internal/... | scripts/colorize-tests.sh
|
||||
test-fast:
|
||||
go test -timeout 5m -v ./internal/...
|
||||
go test -timeout 5m -v ./internal/... | scripts/colorize-tests.sh
|
||||
test-race:
|
||||
go test -tags=slow -race -timeout 60m -v ./internal/...
|
||||
go test -tags=slow -race -timeout 60m -v ./internal/... | scripts/colorize-tests.sh
|
||||
test-codecov:
|
||||
go test -tags=slow -timeout 30m -coverprofile=coverage.txt -covermode=atomic -v ./internal/...
|
||||
scripts/codecov.sh
|
||||
|
|
|
|||
|
|
@ -12,13 +12,14 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
// Returns true if file exists
|
||||
func Exists(filename string) bool {
|
||||
info, err := os.Stat(filename)
|
||||
|
||||
return err == nil && !info.IsDir()
|
||||
}
|
||||
|
||||
// Returns the expanded format for a filename.
|
||||
// Returns full path; ~ replaced with actual home directory
|
||||
func ExpandedFilename(filename string) string {
|
||||
usr, _ := user.Current()
|
||||
dir := usr.HomeDir
|
||||
|
|
@ -36,7 +37,7 @@ func ExpandedFilename(filename string) string {
|
|||
return result
|
||||
}
|
||||
|
||||
|
||||
// Extract Zip file in destination directory
|
||||
func Unzip(src, dest string) ([]string, error) {
|
||||
|
||||
var fileNames []string
|
||||
|
|
@ -103,6 +104,7 @@ func Unzip(src, dest string) ([]string, error) {
|
|||
return fileNames, nil
|
||||
}
|
||||
|
||||
// Download a file from a URL
|
||||
func Download(filepath string, url string) (err error) {
|
||||
os.MkdirAll("/tmp/photoprism", os.ModePerm)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
"os"
|
||||
)
|
||||
|
||||
// Returns sha1 hash of file as string
|
||||
func Hash(filename string) string {
|
||||
var result []byte
|
||||
|
||||
|
|
@ -25,4 +26,4 @@ func Hash(filename string) string {
|
|||
}
|
||||
|
||||
return hex.EncodeToString(hash.Sum(result))
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ package photoprism
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -38,4 +38,3 @@ type Config interface {
|
|||
GetPublicPath() string
|
||||
GetPublicBuildPath() string
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import (
|
|||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/fsutil"
|
||||
"github.com/photoprism/photoprism/internal/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -13,4 +13,4 @@ func TestNewConverter(t *testing.T) {
|
|||
converter := NewConverter(conf.GetDarktableCli())
|
||||
|
||||
assert.IsType(t, &Converter{}, converter)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ package photoprism
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,2 +0,0 @@
|
|||
package photoprism
|
||||
|
||||
|
|
@ -4,6 +4,8 @@ package photoprism
|
|||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/test"
|
||||
)
|
||||
|
||||
func TestImporter_ImportPhotosFromDirectory(t *testing.T) {
|
||||
|
|
@ -20,4 +22,4 @@ func TestImporter_ImportPhotosFromDirectory(t *testing.T) {
|
|||
importer := NewImporter(conf.GetOriginalsPath(), indexer, converter)
|
||||
|
||||
importer.ImportPhotosFromDirectory(conf.GetImportPath())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ package photoprism
|
|||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
|
@ -38,4 +39,4 @@ func TestMediaFile_GetPerceptiveHash_Slow(t *testing.T) {
|
|||
distance, _ = mediaFile1.GetPerceptualDistance(hash3)
|
||||
|
||||
assert.Equal(t, 7, distance)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ import (
|
|||
"io/ioutil"
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/test"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
|
@ -31,4 +32,4 @@ func TestTensorFlow_GetImageTags(t *testing.T) {
|
|||
|
||||
assert.Equal(t, float32(0.1648176), result[1].Probability)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ package photoprism
|
|||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/photoprism/photoprism/internal/test"
|
||||
)
|
||||
|
||||
func TestCreateThumbnailsFromOriginals(t *testing.T) {
|
||||
|
|
|
|||
|
|
@ -39,4 +39,4 @@ func TestMediaFile_GetSquareThumbnail(t *testing.T) {
|
|||
assert.Empty(t, err)
|
||||
|
||||
assert.IsType(t, &MediaFile{}, thumbnail1)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,4 +22,4 @@ func TestConfig_ConnectToDatabase(t *testing.T) {
|
|||
db := c.GetDb()
|
||||
|
||||
assert.IsType(t, &gorm.DB{}, db)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
9
scripts/colorize-tests.sh
Executable file
9
scripts/colorize-tests.sh
Executable file
|
|
@ -0,0 +1,9 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
if (( $# == 0 )) ; then
|
||||
sed ''/PASS/s//$(printf "\033[32mPASS\033[0m")/'' < /dev/stdin | sed ''/FAIL/s//$(printf "\033[31mFAIL\033[0m")/''
|
||||
else
|
||||
sed ''/PASS/s//$(printf "\033[32mPASS\033[0m")/'' <<< "$1" | sed ''/FAIL/s//$(printf "\033[31mFAIL\033[0m")/''
|
||||
fi
|
||||
|
||||
echo "Code that cannot be tested is flawed :-)"
|
||||
Loading…
Add table
Add a link
Reference in a new issue