mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 16:29:12 +00:00

* chore: tidy deps * refactor: database migration * refactor: store release * refactor: save release * chore: add packages * feat(web): show stats and recent releases * refactor: simply filter struct * feat: add eventbus * chore: cleanup logging * chore: update packages
364 lines
8.9 KiB
Go
364 lines
8.9 KiB
Go
package domain
|
|
|
|
import (
|
|
"github.com/stretchr/testify/assert"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestRelease_Parse(t *testing.T) {
|
|
tests := []struct {
|
|
name string
|
|
fields Release
|
|
wantErr bool
|
|
}{
|
|
{name: "parse_1", fields: Release{
|
|
ID: 0,
|
|
Rejections: nil,
|
|
Indexer: "",
|
|
FilterName: "",
|
|
Protocol: "",
|
|
Implementation: "",
|
|
Timestamp: time.Time{},
|
|
TorrentID: "",
|
|
GroupID: "",
|
|
TorrentName: "Servant S01 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-FLUX",
|
|
Raw: "",
|
|
Title: "",
|
|
Category: "",
|
|
Season: 0,
|
|
Episode: 0,
|
|
Year: 0,
|
|
Resolution: "",
|
|
Source: "",
|
|
Codec: "",
|
|
Container: "",
|
|
HDR: "",
|
|
Audio: "",
|
|
Group: "",
|
|
Region: "",
|
|
Edition: "",
|
|
Proper: false,
|
|
Repack: false,
|
|
Website: "",
|
|
Language: "",
|
|
Unrated: false,
|
|
Hybrid: false,
|
|
Size: 0,
|
|
ThreeD: false,
|
|
Artists: nil,
|
|
Type: "",
|
|
Format: "",
|
|
Bitrate: "",
|
|
LogScore: 0,
|
|
HasLog: false,
|
|
HasCue: false,
|
|
IsScene: false,
|
|
Origin: "",
|
|
Tags: nil,
|
|
Freeleech: false,
|
|
FreeleechPercent: 0,
|
|
Uploader: "",
|
|
PreTime: "",
|
|
TorrentURL: "",
|
|
Filter: nil,
|
|
}, wantErr: false},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
r := tt.fields
|
|
if err := r.Parse(); (err != nil) != tt.wantErr {
|
|
t.Errorf("Parse() error = %v, wantErr %v", err, tt.wantErr)
|
|
}
|
|
})
|
|
}
|
|
}
|
|
|
|
func TestRelease_CheckFilter(t *testing.T) {
|
|
type args struct {
|
|
filter Filter
|
|
}
|
|
tests := []struct {
|
|
name string
|
|
fields *Release
|
|
args args
|
|
want bool
|
|
}{
|
|
{
|
|
name: "size_between_max_min",
|
|
fields: &Release{Size: uint64(10000000001)},
|
|
args: args{
|
|
filter: Filter{
|
|
Enabled: true,
|
|
MinSize: "10 GB",
|
|
MaxSize: "20GB",
|
|
},
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "size_larger_than_max",
|
|
fields: &Release{Size: uint64(30000000001)},
|
|
args: args{
|
|
filter: Filter{
|
|
Enabled: true,
|
|
MinSize: "10 GB",
|
|
MaxSize: "20GB",
|
|
},
|
|
},
|
|
want: false,
|
|
},
|
|
//{
|
|
// name: "test_no_size",
|
|
// fields: &Release{Size: uint64(0)},
|
|
// args: args{
|
|
// filter: Filter{
|
|
// Enabled: true,
|
|
// FilterGeneral: FilterGeneral{MinSize: "10 GB", MaxSize: "20GB"},
|
|
// },
|
|
// },
|
|
// want: false, // additional checks
|
|
//},
|
|
{
|
|
name: "movie_parse_1",
|
|
fields: &Release{
|
|
TorrentName: "That Movie 2020 2160p BluRay DD5.1 x264-GROUP1",
|
|
Category: "Movies",
|
|
Freeleech: true,
|
|
Size: uint64(30000000001),
|
|
},
|
|
args: args{
|
|
filter: Filter{
|
|
Enabled: true,
|
|
MatchCategories: "Movies",
|
|
Freeleech: true,
|
|
MinSize: "10 GB",
|
|
MaxSize: "40GB",
|
|
Resolutions: []string{"2160p"},
|
|
Sources: []string{"BluRay"},
|
|
Codecs: []string{"x264"},
|
|
Years: "2020",
|
|
MatchReleaseGroups: "GROUP1",
|
|
},
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "movie_parse_shows",
|
|
fields: &Release{
|
|
TorrentName: "That Movie 2020 2160p BluRay DD5.1 x264-GROUP1",
|
|
Category: "Movies",
|
|
Freeleech: true,
|
|
Size: uint64(30000000001),
|
|
},
|
|
args: args{
|
|
filter: Filter{
|
|
Enabled: true,
|
|
MatchCategories: "Movies",
|
|
Freeleech: true,
|
|
MinSize: "10 GB",
|
|
MaxSize: "40GB",
|
|
Resolutions: []string{"2160p"},
|
|
Sources: []string{"BluRay"},
|
|
Codecs: []string{"x264"},
|
|
Years: "2020",
|
|
MatchReleaseGroups: "GROUP1",
|
|
Shows: "That Movie",
|
|
},
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "movie_parse_multiple_shows",
|
|
fields: &Release{
|
|
TorrentName: "That Movie 2020 2160p BluRay DD5.1 x264-GROUP1",
|
|
Category: "Movies",
|
|
Freeleech: true,
|
|
Size: uint64(30000000001),
|
|
},
|
|
args: args{
|
|
filter: Filter{
|
|
Enabled: true,
|
|
MatchCategories: "Movies",
|
|
Freeleech: true,
|
|
MinSize: "10 GB",
|
|
MaxSize: "40GB",
|
|
Resolutions: []string{"2160p"},
|
|
Sources: []string{"BluRay"},
|
|
Codecs: []string{"x264"},
|
|
Years: "2020",
|
|
MatchReleaseGroups: "GROUP1",
|
|
Shows: "That Movie, good story, bad movie",
|
|
},
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "movie_parse_wildcard_shows",
|
|
fields: &Release{
|
|
TorrentName: "That Movie 2020 2160p BluRay DD5.1 x264-GROUP1",
|
|
Category: "Movies",
|
|
Freeleech: true,
|
|
Size: uint64(30000000001), // 30GB
|
|
},
|
|
args: args{
|
|
filter: Filter{
|
|
Enabled: true,
|
|
MatchCategories: "Movies, tv",
|
|
Freeleech: true,
|
|
MinSize: "10 GB",
|
|
MaxSize: "40GB",
|
|
Resolutions: []string{"1080p", "2160p"},
|
|
Sources: []string{"BluRay"},
|
|
Codecs: []string{"x264"},
|
|
Years: "2015,2018-2022",
|
|
MatchReleaseGroups: "GROUP1,BADGROUP",
|
|
Shows: "*Movie*, good story, bad movie",
|
|
},
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "movie_bad_category",
|
|
fields: &Release{
|
|
TorrentName: "That Movie 2020 2160p BluRay DD5.1 x264-GROUP1",
|
|
Category: "Movies",
|
|
Freeleech: true,
|
|
Size: uint64(30000000001), // 30GB
|
|
},
|
|
args: args{
|
|
filter: Filter{
|
|
Enabled: true,
|
|
MatchCategories: "*tv*",
|
|
Freeleech: true,
|
|
MinSize: "10 GB",
|
|
MaxSize: "40GB",
|
|
Resolutions: []string{"1080p", "2160p"},
|
|
Sources: []string{"BluRay"},
|
|
Codecs: []string{"x264"},
|
|
Years: "2015,2018-2022",
|
|
MatchReleaseGroups: "GROUP1,BADGROUP",
|
|
Shows: "*Movie*, good story, bad movie",
|
|
},
|
|
},
|
|
want: false,
|
|
},
|
|
{
|
|
name: "tv_match_season_episode",
|
|
fields: &Release{
|
|
TorrentName: "Good show S01E01 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
|
Category: "TV",
|
|
},
|
|
args: args{
|
|
filter: Filter{
|
|
Enabled: true,
|
|
MatchCategories: "*tv*",
|
|
Resolutions: []string{"1080p", "2160p"},
|
|
Sources: []string{"WEB-DL"},
|
|
Codecs: []string{"HEVC"},
|
|
MatchReleaseGroups: "GROUP1,GROUP2",
|
|
Seasons: "1,2",
|
|
Episodes: "1",
|
|
},
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "tv_match_season",
|
|
fields: &Release{
|
|
TorrentName: "Good show S01 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
|
Category: "TV",
|
|
},
|
|
args: args{
|
|
filter: Filter{
|
|
Enabled: true,
|
|
MatchCategories: "*tv*",
|
|
Resolutions: []string{"1080p", "2160p"},
|
|
Sources: []string{"WEB-DL"},
|
|
Codecs: []string{"HEVC"},
|
|
MatchReleaseGroups: "GROUP1,GROUP2",
|
|
Seasons: "1,2",
|
|
},
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "tv_bad_match_season",
|
|
fields: &Release{
|
|
TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
|
Category: "TV",
|
|
},
|
|
args: args{
|
|
filter: Filter{
|
|
Enabled: true,
|
|
MatchCategories: "*tv*",
|
|
Resolutions: []string{"1080p", "2160p"},
|
|
Sources: []string{"WEB-DL"},
|
|
Codecs: []string{"HEVC"},
|
|
MatchReleaseGroups: "GROUP1,GROUP2",
|
|
Seasons: "1",
|
|
},
|
|
},
|
|
want: false,
|
|
},
|
|
{
|
|
name: "match_uploader",
|
|
fields: &Release{
|
|
TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
|
Category: "TV",
|
|
Uploader: "Uploader1",
|
|
},
|
|
args: args{
|
|
filter: Filter{
|
|
Enabled: true,
|
|
MatchCategories: "*tv*",
|
|
MatchUploaders: "Uploader1",
|
|
},
|
|
},
|
|
want: true,
|
|
},
|
|
{
|
|
name: "except_uploader",
|
|
fields: &Release{
|
|
TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
|
Category: "TV",
|
|
Uploader: "Anonymous",
|
|
},
|
|
args: args{
|
|
filter: Filter{
|
|
Enabled: true,
|
|
MatchCategories: "*tv*",
|
|
ExceptUploaders: "Anonymous",
|
|
},
|
|
},
|
|
want: false,
|
|
},
|
|
{
|
|
name: "match_except_uploader",
|
|
fields: &Release{
|
|
TorrentName: "Good show S02 2160p ATVP WEB-DL DDP 5.1 Atmos DV HEVC-GROUP2",
|
|
Category: "TV",
|
|
Uploader: "Uploader1",
|
|
},
|
|
args: args{
|
|
filter: Filter{
|
|
Enabled: true,
|
|
MatchCategories: "*tv*",
|
|
MatchUploaders: "Uploader1,Uploader2",
|
|
ExceptUploaders: "Anonymous",
|
|
},
|
|
},
|
|
want: true,
|
|
},
|
|
}
|
|
for _, tt := range tests {
|
|
t.Run(tt.name, func(t *testing.T) {
|
|
r := tt.fields // Release
|
|
|
|
_ = r.Parse() // Parse TorrentName into struct
|
|
got := r.CheckFilter(tt.args.filter)
|
|
|
|
assert.Equal(t, tt.want, got)
|
|
})
|
|
}
|
|
}
|