QBitRun/lib/workflow/job_test.go

91 lines
1.7 KiB
Go

package workflow
import (
"testing"
"github.com/stretchr/testify/assert"
"gopkg.in/yaml.v3"
)
func TestErrorAction_UnmarshalYAML(t *testing.T) {
tests := []struct {
name string
input []byte
want ErrorAction
wantErr bool
}{
{
name: "continue",
input: []byte(`E: ConTinue`),
want: ErrorActionContinue,
},
{
name: "stop-job",
input: []byte(`E: stop-job`),
want: ErrorActionStopJob,
},
{
name: "stop-job",
input: []byte(`E: stop-job`),
want: ErrorActionStopJob,
},
{
name: "null is stop-job",
input: []byte(`E: null`),
want: ErrorActionStopJob,
},
{
name: "unset is stop-job",
input: []byte(`E: `),
want: ErrorActionStopJob,
},
{
name: "whitespace only is stop-job",
input: []byte(`E: " "`),
want: ErrorActionStopJob,
},
{
name: "empty is stop-job",
input: []byte(`E: ""`),
want: ErrorActionStopJob,
},
{
name: "unset is stop-job 2",
input: []byte(`foo: bar`),
want: ErrorActionStopJob,
},
{
name: "stop-action",
input: []byte(`E: stop-action`),
want: ErrorActionStopAction,
},
{
name: "stop-run",
input: []byte(`E: stop-run`),
want: ErrorActionStopRun,
},
{
name: "error on invalid value",
input: []byte(`E: invalid`),
wantErr: true,
},
}
type placeholder struct {
E ErrorAction `yaml:"E"`
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
var placeholder placeholder
err := yaml.Unmarshal(tt.input, &placeholder)
if tt.wantErr {
assert.Error(t, err)
return
}
if !assert.NoError(t, err) {
return
}
assert.Equal(t, tt.want, placeholder.E)
})
}
}