error-action: add marshal yaml
This commit is contained in:
parent
0ad2e1a1e1
commit
44c1f1a629
|
@ -16,6 +16,10 @@ type Job struct {
|
|||
|
||||
type ErrorAction string
|
||||
|
||||
func (er ErrorAction) MarshalYAML() (interface{}, error) {
|
||||
return er.String(), nil
|
||||
}
|
||||
|
||||
func (ea *ErrorAction) UnmarshalYAML(value *yaml.Node) error {
|
||||
if value.IsZero() {
|
||||
*ea = ErrorActionStopJob
|
||||
|
|
|
@ -88,3 +88,45 @@ func TestErrorAction_UnmarshalYAML(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestErrorAction_MarshalYAML(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
er ErrorAction
|
||||
want []byte
|
||||
}{
|
||||
{
|
||||
name: "continue",
|
||||
er: ErrorActionContinue,
|
||||
want: []byte("E: continue"),
|
||||
},
|
||||
{
|
||||
name: "stop-job",
|
||||
er: ErrorActionStopJob,
|
||||
want: []byte("E: stop-job"),
|
||||
},
|
||||
{
|
||||
name: "stop-action",
|
||||
er: ErrorActionStopAction,
|
||||
want: []byte("E: stop-action"),
|
||||
},
|
||||
{
|
||||
name: "stop-run",
|
||||
er: ErrorActionStopRun,
|
||||
want: []byte("E: stop-run"),
|
||||
},
|
||||
}
|
||||
type placeholder struct {
|
||||
E ErrorAction `yaml:"E"`
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
e := placeholder{E: tt.er}
|
||||
got, err := yaml.Marshal(e)
|
||||
if !assert.NoError(t, err) {
|
||||
return
|
||||
}
|
||||
assert.Equal(t, tt.want, got)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue