[wip] error-action: added invalid test case

This commit is contained in:
Tigor Hutasuhut 2024-06-25 16:55:52 +07:00
parent f0feb88d5a
commit 0ad2e1a1e1

View file

@ -9,9 +9,10 @@ import (
func TestErrorAction_UnmarshalYAML(t *testing.T) { func TestErrorAction_UnmarshalYAML(t *testing.T) {
tests := []struct { tests := []struct {
name string name string
input []byte input []byte
want ErrorAction want ErrorAction
wantErr bool
}{ }{
{ {
name: "continue", name: "continue",
@ -63,6 +64,11 @@ func TestErrorAction_UnmarshalYAML(t *testing.T) {
input: []byte(`E: stop-run`), input: []byte(`E: stop-run`),
want: ErrorActionStopRun, want: ErrorActionStopRun,
}, },
{
name: "error on invalid value",
input: []byte(`E: invalid`),
wantErr: true,
},
} }
type placeholder struct { type placeholder struct {
E ErrorAction `yaml:"E"` E ErrorAction `yaml:"E"`
@ -71,6 +77,10 @@ func TestErrorAction_UnmarshalYAML(t *testing.T) {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {
var placeholder placeholder var placeholder placeholder
err := yaml.Unmarshal(tt.input, &placeholder) err := yaml.Unmarshal(tt.input, &placeholder)
if tt.wantErr {
assert.Error(t, err)
return
}
if !assert.NoError(t, err) { if !assert.NoError(t, err) {
return return
} }