mirror of
https://github.com/idanoo/autobrr
synced 2025-07-22 16:29:12 +00:00
feat(actions): simplify macro parsing (#560)
* refactor(action): parse macros * feat(action): add ctx to arr clients and test
This commit is contained in:
parent
f6e68fae2b
commit
839eb9f3f3
31 changed files with 323 additions and 334 deletions
|
@ -9,55 +9,48 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func Test_service_parseExecArgs(t *testing.T) {
|
||||
func Test_service_parseMacros(t *testing.T) {
|
||||
type args struct {
|
||||
release domain.Release
|
||||
execArgs string
|
||||
release domain.Release
|
||||
action *domain.Action
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
args args
|
||||
want []string
|
||||
want string
|
||||
wantErr bool
|
||||
}{
|
||||
{
|
||||
name: "test_1",
|
||||
args: args{
|
||||
release: domain.Release{TorrentName: "Sally Goes to the Mall S04E29"},
|
||||
execArgs: `echo "{{ .TorrentName }}"`,
|
||||
},
|
||||
want: []string{
|
||||
"echo",
|
||||
"Sally Goes to the Mall S04E29",
|
||||
release: domain.Release{TorrentName: "Sally Goes to the Mall S04E29"},
|
||||
action: &domain.Action{
|
||||
ExecArgs: `echo "{{ .TorrentName }}"`,
|
||||
},
|
||||
},
|
||||
want: `echo "Sally Goes to the Mall S04E29"`,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "test_2",
|
||||
args: args{
|
||||
release: domain.Release{TorrentName: "Sally Goes to the Mall S04E29"},
|
||||
execArgs: `"{{ .TorrentName }}"`,
|
||||
},
|
||||
want: []string{
|
||||
"Sally Goes to the Mall S04E29",
|
||||
release: domain.Release{TorrentName: "Sally Goes to the Mall S04E29"},
|
||||
action: &domain.Action{
|
||||
ExecArgs: `"{{ .TorrentName }}"`,
|
||||
},
|
||||
},
|
||||
want: `"Sally Goes to the Mall S04E29"`,
|
||||
wantErr: false,
|
||||
},
|
||||
{
|
||||
name: "test_3",
|
||||
args: args{
|
||||
release: domain.Release{TorrentName: "Sally Goes to the Mall S04E29"},
|
||||
execArgs: `--header "Content-Type: application/json" --request POST --data '{"release":"{{ .TorrentName }}"}' http://localhost:3000/api/release`,
|
||||
},
|
||||
want: []string{
|
||||
"--header",
|
||||
"Content-Type: application/json",
|
||||
"--request",
|
||||
"POST",
|
||||
"--data",
|
||||
`{"release":"Sally Goes to the Mall S04E29"}`,
|
||||
"http://localhost:3000/api/release",
|
||||
release: domain.Release{TorrentName: "Sally Goes to the Mall S04E29"},
|
||||
action: &domain.Action{
|
||||
ExecArgs: `--header "Content-Type: application/json" --request POST --data '{"release":"{{ .TorrentName }}"}' http://localhost:3000/api/release`,
|
||||
},
|
||||
},
|
||||
want: `--header "Content-Type: application/json" --request POST --data '{"release":"Sally Goes to the Mall S04E29"}' http://localhost:3000/api/release`,
|
||||
wantErr: false,
|
||||
},
|
||||
}
|
||||
|
@ -69,8 +62,8 @@ func Test_service_parseExecArgs(t *testing.T) {
|
|||
clientSvc: nil,
|
||||
bus: nil,
|
||||
}
|
||||
got, _ := s.parseExecArgs(tt.args.release, tt.args.execArgs)
|
||||
assert.Equalf(t, tt.want, got, "parseExecArgs(%v, %v)", tt.args.release, tt.args.execArgs)
|
||||
_ = s.parseMacros(tt.args.action, tt.args.release)
|
||||
assert.Equalf(t, tt.want, tt.args.action.ExecArgs, "parseMacros(%v, %v)", tt.args.action, tt.args.release)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -78,7 +71,7 @@ func Test_service_parseExecArgs(t *testing.T) {
|
|||
func Test_service_execCmd(t *testing.T) {
|
||||
type args struct {
|
||||
release domain.Release
|
||||
action domain.Action
|
||||
action *domain.Action
|
||||
}
|
||||
tests := []struct {
|
||||
name string
|
||||
|
@ -92,7 +85,7 @@ func Test_service_execCmd(t *testing.T) {
|
|||
TorrentTmpFile: "tmp-10000",
|
||||
Indexer: "mock",
|
||||
},
|
||||
action: domain.Action{
|
||||
action: &domain.Action{
|
||||
Name: "echo",
|
||||
ExecCmd: "echo",
|
||||
ExecArgs: "hello",
|
||||
|
@ -108,7 +101,7 @@ func Test_service_execCmd(t *testing.T) {
|
|||
clientSvc: nil,
|
||||
bus: nil,
|
||||
}
|
||||
s.execCmd(tt.args.action, tt.args.release)
|
||||
s.execCmd(nil, tt.args.action, tt.args.release)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue