Files
photoview/api/utils/utils_test.go
Kostiantyn d1193c5ca4 Refactoring part 1: Fix some annoying linter warnings in API code (#1064)
* names, constants of reusable strings, removed unneeded `if`, replaced deprecated imports

* more deprecated imports replaced

* What is this?))

* Fix a path and quote a var in Dockerfile

* Addressing review comments

---------

Co-authored-by: Konstantin Koval <kkb@ukr.net>
2024-09-30 14:45:02 +02:00

77 lines
1.8 KiB
Go

package utils_test
import (
"os"
"path"
"testing"
"github.com/photoview/photoview/api/test_utils"
"github.com/photoview/photoview/api/utils"
)
func TestMain(m *testing.M) {
os.Exit(test_utils.IntegrationTestRun(m))
}
func TestIsDirSymlink(t *testing.T) {
test_utils.FilesystemTest(t)
// Prepare a temporary directory for testing purposes
dir, err := os.MkdirTemp("", "testing")
if err != nil {
t.Fatalf("unable to create temp directory for testing")
}
defer os.RemoveAll(dir)
// Create regular file
_, err = os.Create(path.Join(dir, "regular_file"))
if err != nil {
t.Fatalf("unable to create regular file for testing")
}
// Create directory
err = os.Mkdir(path.Join(dir, "directory"), 0755)
if err != nil {
t.Fatalf("unable to create directory for testing")
}
// Create symlink to regular file
err = os.Symlink(path.Join(dir, "regular_file"), path.Join(dir, "file_link"))
if err != nil {
t.Fatalf("unable to create file link for testing")
}
// Create symlink to directory
err = os.Symlink(path.Join(dir, "directory"), path.Join(dir, "dir_link"))
if err != nil {
t.Fatalf("unable to create dir link for testing")
}
// Execute the actual tests
isDirLink, _ := utils.IsDirSymlink(path.Join(dir, "regular_file"))
if isDirLink {
t.Error("Failed detection of regular file")
}
isDirLink, _ = utils.IsDirSymlink(path.Join(dir, "directory"))
if isDirLink {
t.Error("Failed detection of directory")
}
isDirLink, _ = utils.IsDirSymlink(path.Join(dir, "file_link"))
if isDirLink {
t.Error("Failed detection of link to regular file")
}
isDirLink, _ = utils.IsDirSymlink(path.Join(dir, "dir_link"))
if !isDirLink {
t.Error("Failed detection of link to directory")
}
isDirLink, err = utils.IsDirSymlink(path.Join(dir, "non_existant"))
if err == nil {
t.Error("Missing error for non-existant file")
}
}