feat(actions): simplify macro parsing (#560)

* refactor(action): parse macros

* feat(action): add ctx to arr clients and test
This commit is contained in:
ze0s 2022-12-10 21:48:19 +01:00 committed by GitHub
parent f6e68fae2b
commit 839eb9f3f3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
31 changed files with 323 additions and 334 deletions

View file

@ -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)
})
}
}