mirror of
https://github.com/stashapp/stash.git
synced 2025-12-12 03:12:24 +01:00
* Add a space after // comments
For consistency, the commentFormatting lint checker suggests a space
after each // comment block. This commit handles all the spots in
the code where that is needed.
* Rewrite documentation on functions
Use the Go idiom of commenting:
* First sentence declares the purpose.
* First word is the name being declared
The reason this style is preferred is such that grep is able to find
names the user might be interested in. Consider e.g.,
go doc -all pkg/ffmpeg | grep -i transcode
in which case a match will tell you the name of the function you are
interested in.
* Remove old code comment-blocks
There are some commented out old code blocks in the code base. These are
either 3 years old, or 2 years old. By now, I don't think their use is
going to come back any time soon, and Git will track old pieces of
deleted code anyway.
Opt for deletion.
* Reorder imports
Split stdlib imports from non-stdlib imports in files we are touching.
* Use a range over an iteration variable
Probably more go-idiomatic, and the code needed comment-fixing anyway.
* Use time.After rather than rolling our own
The idiom here is common enough that the stdlib contains a function for
it. Use the stdlib function over our own variant.
* Enable the commentFormatting linter
92 lines
2.9 KiB
Go
92 lines
2.9 KiB
Go
package manager
|
|
|
|
import (
|
|
"fmt"
|
|
"testing"
|
|
|
|
"github.com/stashapp/stash/pkg/logger"
|
|
)
|
|
|
|
var excludeTestFilenames = []string{
|
|
"/stash/videos/filename.mp4",
|
|
"/stash/videos/new filename.mp4",
|
|
"filename sample.mp4",
|
|
"/stash/videos/exclude/not wanted.webm",
|
|
"/stash/videos/exclude/not wanted2.webm",
|
|
"/somewhere/trash/not wanted.wmv",
|
|
"/disk2/stash/videos/exclude/!!wanted!!.avi",
|
|
"/disk2/stash/videos/xcl/not wanted.avi",
|
|
"/stash/videos/partial.file.001.webm",
|
|
"/stash/videos/partial.file.002.webm",
|
|
"/stash/videos/partial.file.003.webm",
|
|
"/stash/videos/sample file sample.mkv",
|
|
"/stash/videos/.ckRVp1/.still_encoding.mp4",
|
|
"c:\\stash\\videos\\exclude\\filename windows.mp4",
|
|
"c:\\stash\\videos\\filename windows.mp4",
|
|
"\\\\network\\videos\\filename windows network.mp4",
|
|
"\\\\network\\share\\windows network wanted.mp4",
|
|
"\\\\network\\share\\windows network wanted sample.mp4",
|
|
"\\\\network\\private\\windows.network.skip.mp4"}
|
|
|
|
var excludeTests = []struct {
|
|
testPattern []string
|
|
expected int
|
|
}{
|
|
{[]string{"sample\\.mp4$", "trash", "\\.[\\d]{3}\\.webm$"}, 6}, // generic
|
|
{[]string{"no_match\\.mp4"}, 0}, // no match
|
|
{[]string{"^/stash/videos/exclude/", "/videos/xcl/"}, 3}, // linux
|
|
{[]string{"/\\.[[:word:]]+/"}, 1}, // linux hidden dirs (handbrake unraid issue?)
|
|
{[]string{"c:\\\\stash\\\\videos\\\\exclude"}, 1}, // windows
|
|
{[]string{"\\/[/invalid"}, 0}, // invalid pattern
|
|
{[]string{"\\/[/invalid", "sample\\.[[:alnum:]]+$"}, 3}, // invalid pattern but continue
|
|
{[]string{"^\\\\\\\\network"}, 4}, // windows net share
|
|
{[]string{"\\\\private\\\\"}, 1}, // windows net share
|
|
{[]string{"\\\\private\\\\", "sample\\.mp4"}, 3}, // windows net share
|
|
}
|
|
|
|
func TestExcludeFiles(t *testing.T) {
|
|
for _, test := range excludeTests {
|
|
err := runExclude(excludeTestFilenames, test.testPattern, test.expected)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func runExclude(filenames []string, patterns []string, expCount int) error {
|
|
|
|
files, count := excludeFiles(filenames, patterns)
|
|
|
|
if count != expCount {
|
|
return fmt.Errorf("Was expecting %d, found %d", expCount, count)
|
|
}
|
|
if len(files) != len(filenames)-expCount {
|
|
return fmt.Errorf("Returned list should have %d files, not %d ", len(filenames)-expCount, len(files))
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func TestMatchFile(t *testing.T) {
|
|
for _, test := range excludeTests {
|
|
err := runMatch(excludeTestFilenames, test.testPattern, test.expected)
|
|
if err != nil {
|
|
t.Error(err)
|
|
}
|
|
}
|
|
}
|
|
|
|
func runMatch(filenames []string, patterns []string, expCount int) error {
|
|
count := 0
|
|
for _, file := range filenames {
|
|
if matchFile(file, patterns) {
|
|
logger.Infof("File \"%s\" matched pattern\n", file)
|
|
count++
|
|
}
|
|
}
|
|
if count != expCount {
|
|
return fmt.Errorf("Was expecting %d, found %d", expCount, count)
|
|
}
|
|
|
|
return nil
|
|
}
|