internal/kobject: improve error JSON representation
All checks were successful
Test / Create distribution (push) Successful in 1m4s
Test / Sandbox (push) Successful in 2m55s
Test / Hakurei (push) Successful in 3m52s
Test / ShareFS (push) Successful in 3m44s
Test / Sandbox (race detector) (push) Successful in 5m25s
Test / Hakurei (race detector) (push) Successful in 6m35s
Test / Flake checks (push) Successful in 1m22s
All checks were successful
Test / Create distribution (push) Successful in 1m4s
Test / Sandbox (push) Successful in 2m55s
Test / Hakurei (push) Successful in 3m52s
Test / ShareFS (push) Successful in 3m44s
Test / Sandbox (race detector) (push) Successful in 5m25s
Test / Hakurei (race detector) (push) Successful in 6m35s
Test / Flake checks (push) Successful in 1m22s
This is now usable by internal/report. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
@@ -42,12 +42,12 @@ func TestConsume(t *testing.T) {
|
||||
"SYNTH_UUID=fdfdfdfd-fdfd-fdfd-fdfd-fdfdfdfdfdfd",
|
||||
}},
|
||||
}, map[string]*Object{}, nil, []error{
|
||||
UnexpectedColdbootError{
|
||||
(&Event{
|
||||
Action: uevent.KOBJ_BIND,
|
||||
DevPath: "\x00",
|
||||
Env: map[string]string{},
|
||||
Synth: &coldboot,
|
||||
},
|
||||
}).NewError(EUnexpectedColdboot, nil),
|
||||
}},
|
||||
|
||||
{"sequence", []*uevent.Message{
|
||||
@@ -85,12 +85,16 @@ func TestConsume(t *testing.T) {
|
||||
Env: map[string]string{"V": "\xfd"},
|
||||
},
|
||||
}, nil, []error{
|
||||
DuplicateAddError{
|
||||
(&Event{
|
||||
Action: uevent.KOBJ_ADD,
|
||||
DevPath: "\x00",
|
||||
Env: map[string]string{"V": "\xfd"},
|
||||
Sequence: 2,
|
||||
},
|
||||
}).NewError(EDuplicateAdd, &Object{
|
||||
State: StateNew,
|
||||
DevPath: "\x00",
|
||||
Env: map[string]string{"V": "\xff"},
|
||||
}),
|
||||
}},
|
||||
|
||||
{"remove", []*uevent.Message{
|
||||
@@ -109,16 +113,21 @@ func TestConsume(t *testing.T) {
|
||||
"SEQNUM=3",
|
||||
}},
|
||||
}, map[string]*Object{}, nil, []error{
|
||||
TargetError{
|
||||
(&Event{
|
||||
Action: uevent.KOBJ_REMOVE,
|
||||
DevPath: "\x00",
|
||||
Env: map[string]string{},
|
||||
},
|
||||
RemoveStateError{
|
||||
}).NewError(EBadTarget, nil),
|
||||
(&Event{
|
||||
Action: uevent.KOBJ_REMOVE,
|
||||
DevPath: "\x00",
|
||||
Env: map[string]string{},
|
||||
Sequence: 3,
|
||||
}).NewError(ERemoveState, &Object{
|
||||
State: StateBound,
|
||||
DevPath: "\x00",
|
||||
Driver: "\xfd",
|
||||
},
|
||||
}),
|
||||
}},
|
||||
|
||||
{"change", []*uevent.Message{
|
||||
@@ -133,14 +142,14 @@ func TestConsume(t *testing.T) {
|
||||
Env: map[string]string{"V": "\xff"},
|
||||
},
|
||||
}, nil, []error{
|
||||
TargetError{
|
||||
(&Event{
|
||||
Action: uevent.KOBJ_CHANGE,
|
||||
DevPath: "\x00",
|
||||
Sequence: 9,
|
||||
Env: map[string]string{
|
||||
"V": "\xff",
|
||||
},
|
||||
},
|
||||
}).NewError(EBadTarget, nil),
|
||||
}},
|
||||
|
||||
{"move", []*uevent.Message{
|
||||
@@ -157,14 +166,14 @@ func TestConsume(t *testing.T) {
|
||||
"\x0f": {DevPath: "\x0f", Env: map[string]string{"V": "\xfc"}},
|
||||
"\x0e": {DevPath: "\x0e", Env: map[string]string{"V": "\xfd"}},
|
||||
}, nil, []error{
|
||||
MalformedMoveError{
|
||||
(&Event{
|
||||
Action: uevent.KOBJ_MOVE,
|
||||
DevPath: "\x0f",
|
||||
Env: map[string]string{
|
||||
"V": "\xfc",
|
||||
},
|
||||
},
|
||||
TargetError{
|
||||
}).NewError(EMalformedMove, nil),
|
||||
(&Event{
|
||||
Action: uevent.KOBJ_MOVE,
|
||||
DevPath: "\x0e",
|
||||
Env: map[string]string{
|
||||
@@ -172,7 +181,7 @@ func TestConsume(t *testing.T) {
|
||||
"DEVPATH_OLD": "\xff",
|
||||
},
|
||||
Sequence: 1,
|
||||
},
|
||||
}).NewError(EBadTarget, nil),
|
||||
}},
|
||||
|
||||
{"offline", []*uevent.Message{
|
||||
@@ -203,31 +212,43 @@ func TestConsume(t *testing.T) {
|
||||
Env: map[string]string{"V": "\xf0"},
|
||||
},
|
||||
}, nil, []error{
|
||||
TargetError{
|
||||
(&Event{
|
||||
Action: uevent.KOBJ_ONLINE,
|
||||
DevPath: "\xfd",
|
||||
Env: map[string]string{
|
||||
"V": "\xff",
|
||||
},
|
||||
Sequence: 9,
|
||||
},
|
||||
UnexpectedOfflineError{
|
||||
}).NewError(EBadTarget, nil),
|
||||
(&Event{
|
||||
Action: uevent.KOBJ_ONLINE,
|
||||
DevPath: "\xfd",
|
||||
Env: map[string]string{
|
||||
"V": "\xff",
|
||||
},
|
||||
},
|
||||
UnexpectedOfflineError{
|
||||
Sequence: 9,
|
||||
}).NewError(EUnexpectedOffline, &Object{
|
||||
DevPath: "\xfd",
|
||||
Env: map[string]string{
|
||||
"V": "\xff",
|
||||
},
|
||||
}),
|
||||
(&Event{
|
||||
Action: uevent.KOBJ_OFFLINE,
|
||||
DevPath: "\xfd",
|
||||
Env: map[string]string{},
|
||||
Sequence: 11,
|
||||
}).NewError(EUnexpectedOffline, &Object{
|
||||
Offline: true,
|
||||
DevPath: "\xfd",
|
||||
Env: map[string]string{"V": "\xff"},
|
||||
},
|
||||
TargetError{
|
||||
}),
|
||||
(&Event{
|
||||
Action: uevent.KOBJ_OFFLINE,
|
||||
DevPath: "\xfc",
|
||||
Env: map[string]string{"V": "\xf0"},
|
||||
Sequence: 12,
|
||||
},
|
||||
}).NewError(EBadTarget, nil),
|
||||
}},
|
||||
|
||||
{"bind", []*uevent.Message{
|
||||
@@ -272,22 +293,32 @@ func TestConsume(t *testing.T) {
|
||||
"V": "\xf0",
|
||||
},
|
||||
}}, nil, []error{
|
||||
UnbindStateError{
|
||||
(&Event{
|
||||
Action: uevent.KOBJ_UNBIND,
|
||||
DevPath: "\x00",
|
||||
Env: map[string]string{"_V": "\xfd"},
|
||||
Sequence: 2,
|
||||
}).NewError(EUnbindState, &Object{
|
||||
State: StateNew,
|
||||
DevPath: "\x00",
|
||||
Env: map[string]string{"V": "\xff"},
|
||||
},
|
||||
BindStateError{
|
||||
}),
|
||||
(&Event{
|
||||
Action: uevent.KOBJ_BIND,
|
||||
DevPath: "\x00",
|
||||
Env: map[string]string{"___V": "\xfb"},
|
||||
Sequence: 4,
|
||||
}).NewError(EBindState, &Object{
|
||||
State: StateBound,
|
||||
DevPath: "\x00",
|
||||
Env: map[string]string{"V": "\xff", "__V": "\xfc"},
|
||||
},
|
||||
TargetError{
|
||||
}),
|
||||
(&Event{
|
||||
Action: uevent.KOBJ_BIND,
|
||||
DevPath: "\f",
|
||||
Env: map[string]string{"V": "\xf0", "DRIVER": "\x01"},
|
||||
Sequence: 5,
|
||||
},
|
||||
}).NewError(EBadTarget, nil),
|
||||
}},
|
||||
|
||||
{"unbind", []*uevent.Message{
|
||||
@@ -295,12 +326,12 @@ func TestConsume(t *testing.T) {
|
||||
"SEQNUM=9",
|
||||
}},
|
||||
}, map[string]*Object{}, nil, []error{
|
||||
TargetError{
|
||||
(&Event{
|
||||
Action: uevent.KOBJ_UNBIND,
|
||||
DevPath: "\xfd",
|
||||
Env: map[string]string{},
|
||||
Sequence: 9,
|
||||
},
|
||||
}).NewError(EBadTarget, nil),
|
||||
}},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
@@ -375,7 +406,7 @@ func TestIter(t *testing.T) {
|
||||
var done bool
|
||||
wg.Go(func() {
|
||||
s.Range(ctx, func(o *Object) bool {
|
||||
got = append(got, new(o.Clone()))
|
||||
got = append(got, o.Clone())
|
||||
return !done
|
||||
})
|
||||
})
|
||||
@@ -435,46 +466,75 @@ func TestErrors(t *testing.T) {
|
||||
Want: 0xbabe,
|
||||
}, "SEQNUM=51966, want 47806"},
|
||||
|
||||
{"UnexpectedColdbootError", UnexpectedColdbootError{
|
||||
{"EUnexpectedColdboot", (&Event{
|
||||
Action: 0xbeef,
|
||||
}, "unexpected unsupported kobject_action 48879 coldboot event"},
|
||||
}).NewError(EUnexpectedColdboot, nil),
|
||||
"unexpected unsupported kobject_action 48879 coldboot event"},
|
||||
|
||||
{"DuplicateAddError", DuplicateAddError{
|
||||
{"EDuplicateAdd", (&Event{
|
||||
Action: uevent.KOBJ_ADD,
|
||||
DevPath: "\x00",
|
||||
}, `duplicate add event on devpath "\x00"`},
|
||||
}).NewError(EDuplicateAdd, nil),
|
||||
`duplicate add event on devpath "\x00"`},
|
||||
|
||||
{"TargetError", TargetError{
|
||||
{"EBadTarget", (&Event{
|
||||
Action: uevent.KOBJ_UNBIND,
|
||||
DevPath: "\x00",
|
||||
}, `unexpected unbind event on devpath "\x00"`},
|
||||
}).NewError(EBadTarget, nil),
|
||||
`unexpected unbind event on devpath "\x00"`},
|
||||
|
||||
{"RemoveStateError", RemoveStateError{
|
||||
State: StateBound,
|
||||
{"ERemoveState", (&Event{
|
||||
DevPath: "\x00",
|
||||
}, `remove event targeting devpath "\x00" in state 2`},
|
||||
}).NewError(ERemoveState, &Object{
|
||||
State: StateBound,
|
||||
}), `remove event targeting devpath "\x00" in state 2`},
|
||||
{"ERemoveState invalid", (&Event{
|
||||
DevPath: "\x00",
|
||||
}).NewError(ERemoveState, nil),
|
||||
"invalid remove event error"},
|
||||
|
||||
{"BindStateError", BindStateError{
|
||||
State: StateBound,
|
||||
{"EBindState", (&Event{
|
||||
DevPath: "\x00",
|
||||
}, `bind event targeting devpath "\x00" in state 2`},
|
||||
}).NewError(EBindState, &Object{
|
||||
State: StateBound,
|
||||
}), `bind event targeting devpath "\x00" in state 2`},
|
||||
{"EBindState invalid", (&Event{
|
||||
DevPath: "\x00",
|
||||
}).NewError(EBindState, nil),
|
||||
"invalid bind state error"},
|
||||
|
||||
{"UnbindStateError", UnbindStateError{
|
||||
State: StateNew,
|
||||
{"EUnbindState", (&Event{
|
||||
DevPath: "\x00",
|
||||
}, `unbind event targeting devpath "\x00" in state 1`},
|
||||
}).NewError(EUnbindState, &Object{
|
||||
State: StateNew,
|
||||
}), `unbind event targeting devpath "\x00" in state 1`},
|
||||
{"EUnbindState invalid", (&Event{
|
||||
DevPath: "\x00",
|
||||
}).NewError(EUnbindState, nil),
|
||||
"invalid unbind state error"},
|
||||
|
||||
{"MalformedMoveError", MalformedMoveError{
|
||||
{"EMalformedMove", (&Event{
|
||||
DevPath: "\x00",
|
||||
}, `move event targeting devpath "\x00" missing DEVPATH_OLD`},
|
||||
}).NewError(EMalformedMove, nil),
|
||||
`move event targeting devpath "\x00" missing DEVPATH_OLD`},
|
||||
|
||||
{"UnexpectedOfflineError", UnexpectedOfflineError{
|
||||
{"EUnexpectedOffline", (&Event{
|
||||
DevPath: "\x00",
|
||||
}, `online event targeting devpath "\x00"`},
|
||||
{"UnexpectedOfflineError offline", UnexpectedOfflineError{
|
||||
}).NewError(EUnexpectedOffline, &Object{
|
||||
Offline: false,
|
||||
}), `online event targeting devpath "\x00"`},
|
||||
{"EUnexpectedOffline offline", (&Event{
|
||||
DevPath: "\x00",
|
||||
}).NewError(EUnexpectedOffline, &Object{
|
||||
Offline: true,
|
||||
}, `offline event targeting devpath "\x00"`},
|
||||
}), `offline event targeting devpath "\x00"`},
|
||||
{"EUnexpectedOffline invalid", (&Event{
|
||||
DevPath: "\x00",
|
||||
}).NewError(EUnexpectedOffline, nil),
|
||||
"invalid unexpected offline error"},
|
||||
|
||||
{"EventError invalid", &EventError{Kind: 0xbad},
|
||||
"invalid event error kind 2989"},
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
@@ -1648,13 +1708,13 @@ func TestConsumeSample(t *testing.T) {
|
||||
delete(want, "/devices/virtual/net/lo")
|
||||
o.DevPath = "/devices/virtual/net/_lo"
|
||||
o.Env["INTERFACE"] = "_lo"
|
||||
want["/devices/virtual/net/_lo"] = &o
|
||||
want["/devices/virtual/net/_lo"] = o
|
||||
}, nil},
|
||||
|
||||
{"cpu", testdata02, func(want map[string]*Object) {
|
||||
o := want["/devices/system/machinecheck/machinecheck0"].Clone()
|
||||
o.State = StateNew
|
||||
want["/devices/system/machinecheck/machinecheck0"] = &o
|
||||
want["/devices/system/machinecheck/machinecheck0"] = o
|
||||
}, nil},
|
||||
|
||||
{"loop", testdata03, func(want map[string]*Object) {
|
||||
|
||||
Reference in New Issue
Block a user