github.com/goravel/framework@v1.13.9/queue/task_test.go (about)

     1  package queue
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  
     8  	"github.com/goravel/framework/contracts/queue"
     9  	"github.com/goravel/framework/support/file"
    10  	testingfile "github.com/goravel/framework/testing/file"
    11  )
    12  
    13  type Test struct {
    14  }
    15  
    16  //Signature The name and signature of the job.
    17  func (receiver *Test) Signature() string {
    18  	return "test"
    19  }
    20  
    21  //Handle Execute the job.
    22  func (receiver *Test) Handle(args ...any) error {
    23  	return file.Create("test.txt", args[0].(string))
    24  }
    25  
    26  func TestDispatchSync(t *testing.T) {
    27  	task := &Task{
    28  		jobs: []queue.Jobs{
    29  			{
    30  				Job: &Test{},
    31  				Args: []queue.Arg{
    32  					{Type: "uint64", Value: "test"},
    33  				},
    34  			},
    35  		},
    36  	}
    37  
    38  	err := task.DispatchSync()
    39  	assert.Nil(t, err)
    40  	assert.True(t, file.Exists("test.txt"))
    41  	assert.True(t, testingfile.GetLineNum("test.txt") == 1)
    42  	assert.Nil(t, file.Remove("test.txt"))
    43  }