| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- package device
- import (
- "testing"
- "time"
- hthv1 "hth/internal/gen/hth/api/v1"
- "hth/internal/protocol"
- )
- func FuzzActionRecordConversion(f *testing.F) {
- f.Add("cmd-1", "client:apply", uint64(1), uint64(1), int32(1000), int32(1000), int32(42))
- f.Add("hb", "daemon/internal:heartbeat", uint64(2), uint64(3), int32(0), int32(0), int32(0))
- f.Fuzz(func(t *testing.T, cmd, origin string, epoch, gen uint64, uid, gid, pid int32) {
- if len(cmd) > 128 {
- cmd = cmd[:128]
- }
- if len(origin) > 128 {
- origin = origin[:128]
- }
- ax := ActionExecutionContext{
- CommandID: cmd, Origin: origin, Mode: hthv1.ActionMode_ACTION_MODE_NORMAL,
- DeviceEpoch: epoch, PortGeneration: gen, JobID: 7,
- PeerUID: uid, PeerGID: gid, PeerPID: pid,
- RequestedAt: time.Unix(1, 0), QueuedAt: time.Unix(1, 1),
- EffectiveTarget: protocol.SetAll{Fan: [4]uint8{10, 10, 10, 10}},
- }
- rec := recordFromAction(ax, time.Unix(2, 0), hthv1.ConfirmationStatus_CONFIRMATION_STATUS_UNCONFIRMED,
- hthv1.ActionDispatchState_ACTION_DISPATCH_STATE_UNCONFIRMED)
- if rec == nil {
- return
- }
- if rec.Origin != origin {
- t.Fatalf("origin %q != %q", rec.Origin, origin)
- }
- if rec.ActionEpoch != epoch || rec.PortGeneration != gen {
- t.Fatalf("epoch/gen %d/%d != %d/%d", rec.ActionEpoch, rec.PortGeneration, epoch, gen)
- }
- if rec.PeerUid != uid || rec.PeerGid != gid || rec.PeerPid != pid {
- t.Fatalf("peer mutated")
- }
- })
- }
|