github.com/onflow/flow-go@v0.35.7-crescendo-preview.23-atree-inlining/module/state_synchronization/requester/jobs/jobs_test.go (about) 1 package jobs_test 2 3 import ( 4 "testing" 5 6 "github.com/stretchr/testify/assert" 7 8 "github.com/onflow/flow-go/module" 9 "github.com/onflow/flow-go/module/jobqueue" 10 "github.com/onflow/flow-go/module/state_synchronization/requester/jobs" 11 "github.com/onflow/flow-go/utils/unittest" 12 ) 13 14 func TestBlockEntryJob(t *testing.T) { 15 blockEntry := &jobs.BlockEntry{ 16 Height: 42, 17 BlockID: unittest.IdentifierFixture(), 18 } 19 20 job := jobs.BlockEntryToJob(blockEntry) 21 t.Run("job is correct type", func(t *testing.T) { 22 assert.IsType(t, &jobs.BlockEntryJob{}, job, "job is not a block entry job") 23 }) 24 25 t.Run("job ID matches block ID", func(t *testing.T) { 26 jobID := jobqueue.JobID(blockEntry.BlockID) 27 assert.Equal(t, job.ID(), jobID, "job ID is not the block ID") 28 }) 29 30 t.Run("job converts to block entry", func(t *testing.T) { 31 e, err := jobs.JobToBlockEntry(job) 32 assert.NoError(t, err, "unexpected error converting notify job to block entry") 33 assert.Equal(t, blockEntry, e, "converted block entry is not the same as the original block entry") 34 }) 35 36 t.Run("incorrect job type fails to convert to block entry", func(t *testing.T) { 37 e, err := jobs.JobToBlockEntry(invalidJob{}) 38 assert.Error(t, err, "expected error converting invalidJob to block entry") 39 assert.Nil(t, e, "expected nil block entry") 40 }) 41 } 42 43 type invalidJob struct{} 44 45 func (j invalidJob) ID() module.JobID { 46 return "invalid" 47 }