2019-03-23 22:40:56 +01:00
|
|
|
/*
|
2020-04-14 01:08:07 +02:00
|
|
|
* Copyright (C) 2020 Philipp Haefelfinger (http://www.haefelfinger.ch/). All Rights Reserved.
|
2019-03-23 22:40:56 +01:00
|
|
|
* This application is licensed under GPLv2. See the LICENSE file in the root directory of the project.
|
|
|
|
*/
|
|
|
|
|
2019-03-23 22:05:25 +01:00
|
|
|
package localFileStructure
|
|
|
|
|
|
|
|
import "testing"
|
|
|
|
|
|
|
|
func Test_ScanLocalFileStructure_should_find_testfile(t *testing.T) {
|
2020-04-14 01:08:07 +02:00
|
|
|
supportedExtensions := make([]string, 0)
|
|
|
|
supportedExtensions = append(supportedExtensions, "jpg")
|
2019-03-23 22:05:25 +01:00
|
|
|
|
2020-04-14 23:13:46 +02:00
|
|
|
images, err := ScanLocalFileStructure("../../../test/", supportedExtensions, make([]string, 0), 0)
|
2019-03-23 22:05:25 +01:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
2020-04-14 01:08:07 +02:00
|
|
|
if len(images) != 2 { // 1x folder, 1x image
|
2019-03-23 22:05:25 +01:00
|
|
|
t.Error("Did not find expected testfiles. Expected at least one!")
|
|
|
|
}
|
|
|
|
|
2020-04-14 01:08:07 +02:00
|
|
|
containsTestImage := false
|
2019-03-23 22:05:25 +01:00
|
|
|
for _, img := range images {
|
2020-04-14 01:08:07 +02:00
|
|
|
if img.Name == "testimage.jpg" {
|
|
|
|
containsTestImage = true
|
2019-03-23 22:05:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-14 01:08:07 +02:00
|
|
|
if !containsTestImage {
|
|
|
|
t.Errorf("Did not find the expected testimage.")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-14 23:13:46 +02:00
|
|
|
func Test_ScanLocalFileStructure_should_find_testfile_with_trimmed_folder(t *testing.T) {
|
|
|
|
supportedExtensions := make([]string, 0)
|
|
|
|
supportedExtensions = append(supportedExtensions, "jpg")
|
|
|
|
|
|
|
|
images, err := ScanLocalFileStructure("../../../test/", supportedExtensions, make([]string, 0), 1)
|
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(images) != 2 { // 1x folder, 1x image
|
|
|
|
t.Error("Did not find expected testfiles. Expected at least one!")
|
|
|
|
}
|
|
|
|
|
|
|
|
containsTestImage := false
|
2020-04-16 00:18:56 +02:00
|
|
|
containsFolder := false
|
2020-04-14 23:13:46 +02:00
|
|
|
for _, img := range images {
|
|
|
|
if img.Name == "testimage.jpg" && img.Key == "root/testimage.jpg" && !img.IsDir {
|
|
|
|
containsTestImage = true
|
|
|
|
}
|
|
|
|
|
|
|
|
if img.IsDir && img.Key == "root" {
|
|
|
|
containsFolder = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if !containsTestImage {
|
|
|
|
t.Errorf("Did not find the expected testimage.")
|
|
|
|
}
|
|
|
|
if !containsFolder {
|
2020-04-16 00:18:56 +02:00
|
|
|
t.Errorf("There should be a virtual 'root' folder present.")
|
2020-04-14 23:13:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-04-14 01:08:07 +02:00
|
|
|
func Test_ScanLocalFileStructure_should_ignore_test_directory(t *testing.T) {
|
|
|
|
supportedExtensions := make([]string, 0)
|
|
|
|
supportedExtensions = append(supportedExtensions, "jpg")
|
|
|
|
|
|
|
|
ignores := make([]string, 0)
|
|
|
|
ignores = append(ignores, "images")
|
2020-04-14 23:13:46 +02:00
|
|
|
images, err := ScanLocalFileStructure("../../../test/", supportedExtensions, ignores, 0)
|
2020-04-14 01:08:07 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(images) != 0 {
|
|
|
|
t.Error("Did find expected testfiles. Expected no files as test folder is excluded!")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func Test_ScanLocalFileStructure_should_not_find_jpg_when_only_png_supported(t *testing.T) {
|
|
|
|
supportedExtensions := make([]string, 0)
|
|
|
|
supportedExtensions = append(supportedExtensions, "png")
|
|
|
|
|
2020-04-14 23:13:46 +02:00
|
|
|
images, err := ScanLocalFileStructure("../../../test/", supportedExtensions, make([]string, 0), 0)
|
2020-04-14 01:08:07 +02:00
|
|
|
if err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(images) != 1 {
|
|
|
|
t.Error("Did find expected testfiles. Expected no files as extension is not supported!")
|
|
|
|
}
|
|
|
|
|
|
|
|
containsTestImage := false
|
|
|
|
for _, img := range images {
|
|
|
|
if img.Name == "testimage.jpg" {
|
|
|
|
containsTestImage = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if containsTestImage {
|
|
|
|
t.Errorf("Did find the testimage. This should not happen as png is searched but jpg found")
|
|
|
|
}
|
2019-03-23 22:05:25 +01:00
|
|
|
}
|