Tests: Add tests for internal/photoprism

This commit is contained in:
theresa 2021-03-02 11:59:52 +01:00
parent f5e41c9350
commit 59512b0e50
5 changed files with 111 additions and 2 deletions

BIN
assets/examples/example.mp4 Normal file

Binary file not shown.

View file

@ -20,3 +20,24 @@ func TestFileName(t *testing.T) {
})
}
func TestCacheName(t *testing.T) {
t.Run("cacheKey empty", func(t *testing.T) {
r, err := CacheName("abcdghoj", "test", "")
assert.Error(t, err)
assert.Empty(t, r)
})
t.Run("success", func(t *testing.T) {
r, err := CacheName("abcdghoj", "test", "juh")
if err != nil {
t.Fatal(err)
}
assert.Contains(t, r, "test/a/b/c/abcdghoj_juh")
})
t.Run("filehash too short", func(t *testing.T) {
r, err := CacheName("ab", "test", "juh")
assert.Error(t, err)
assert.Empty(t, r)
})
}

View file

@ -50,5 +50,28 @@ func TestIndex_MediaFile(t *testing.T) {
result := ind.MediaFile(nil, indexOpt, "blue-go-video.mp4")
assert.Equal(t, IndexStatus("failed"), result.Status)
})
}
func TestIndexResult_Archived(t *testing.T) {
t.Run("true", func(t *testing.T) {
r := &IndexResult{IndexArchived, nil, 5, "", 5, ""}
assert.True(t, r.Archived())
})
t.Run("false", func(t *testing.T) {
r := &IndexResult{IndexAdded, nil, 5, "", 5, ""}
assert.False(t, r.Archived())
})
}
func TestIndexResult_Skipped(t *testing.T) {
t.Run("true", func(t *testing.T) {
r := &IndexResult{IndexSkipped, nil, 5, "", 5, ""}
assert.True(t, r.Skipped())
})
t.Run("false", func(t *testing.T) {
r := &IndexResult{IndexAdded, nil, 5, "", 5, ""}
assert.False(t, r.Skipped())
})
}

View file

@ -18,3 +18,10 @@ func TestIndexOptions_SkipUnchanged(t *testing.T) {
result.Rescan = true
assert.False(t, result.SkipUnchanged())
}
func TestIndexOptionsSingle(t *testing.T) {
r := IndexOptionsSingle()
assert.Equal(t, false, r.Stack)
assert.Equal(t, true, r.Convert)
assert.Equal(t, true, r.Rescan)
}

View file

@ -417,7 +417,7 @@ func TestMediaFile_RelatedFiles(t *testing.T) {
t.Fatal(err)
}
assert.Len(t, related.Files, 5)
assert.Len(t, related.Files, 6)
assert.True(t, related.ContainsJpeg())
for _, result := range related.Files {
@ -647,6 +647,37 @@ func TestMediaFile_RootRelName(t *testing.T) {
})
}
func TestMediaFile_RootRelPath(t *testing.T) {
conf := config.TestConfig()
mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/tree_white.jpg")
mediaFile.fileRoot = entity.RootImport
if err != nil {
t.Fatal(err)
}
t.Run("examples_path", func(t *testing.T) {
path := mediaFile.RootRelPath()
assert.Equal(t, conf.ExamplesPath(), path)
})
}
func TestMediaFile_RootPath(t *testing.T) {
conf := config.TestConfig()
mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/tree_white.jpg")
if err != nil {
t.Fatal(err)
}
mediaFile.fileRoot = entity.RootImport
t.Run("examples_path", func(t *testing.T) {
path := mediaFile.RootPath()
assert.Contains(t, path, "import")
})
}
func TestMediaFile_RelName(t *testing.T) {
conf := config.TestConfig()
@ -1416,6 +1447,17 @@ func TestMediaFile_HasJpeg(t *testing.T) {
t.Fatal(err)
}
assert.True(t, f.HasJpeg())
})
t.Run("Random.docx with jpg", func(t *testing.T) {
conf := config.TestConfig()
f, err := NewMediaFile(conf.ExamplesPath() + "/Random.docx")
f.hasJpeg = true
if err != nil {
t.Fatal(err)
}
assert.True(t, f.HasJpeg())
})
}
@ -1575,6 +1617,22 @@ func TestMediaFile_decodeDimension(t *testing.T) {
assert.Equal(t, 1920, mediaFile.Width())
assert.Equal(t, 1080, mediaFile.Height())
})
t.Run("blue-go-video.mp4 with orientation >4 and <8", func(t *testing.T) {
conf := config.TestConfig()
mediaFile, err := NewMediaFile(conf.ExamplesPath() + "/blue-go-video.mp4")
mediaFile.metaData.Orientation = 5
if err != nil {
t.Fatal(err)
}
if err := mediaFile.decodeDimensions(); err != nil {
t.Fatal(err)
}
assert.Equal(t, 1080, mediaFile.Width())
assert.Equal(t, 1920, mediaFile.Height())
})
}
func TestMediaFile_Width(t *testing.T) {