github.com/songzhibin97/gkit@v1.2.13/distributed/task/workflow_test.go (about)

     1  package task
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/stretchr/testify/assert"
     7  )
     8  
     9  func TestNewChain(t *testing.T) {
    10  	t.Parallel()
    11  
    12  	task1 := Signature{
    13  		Name: "foo",
    14  		Args: []Arg{
    15  			{
    16  				Type:  "float64",
    17  				Value: interface{}(1),
    18  			},
    19  			{
    20  				Type:  "float64",
    21  				Value: interface{}(1),
    22  			},
    23  		},
    24  	}
    25  
    26  	task2 := Signature{
    27  		Name: "bar",
    28  		Args: []Arg{
    29  			{
    30  				Type:  "float64",
    31  				Value: interface{}(5),
    32  			},
    33  			{
    34  				Type:  "float64",
    35  				Value: interface{}(6),
    36  			},
    37  		},
    38  	}
    39  
    40  	task3 := Signature{
    41  		Name: "qux",
    42  		Args: []Arg{
    43  			{
    44  				Type:  "float64",
    45  				Value: interface{}(4),
    46  			},
    47  		},
    48  	}
    49  
    50  	chain, err := NewChain("", &task1, &task2, &task3)
    51  	if err != nil {
    52  		t.Fatal(err)
    53  	}
    54  
    55  	firstTask := chain.Tasks[0]
    56  
    57  	assert.Equal(t, "foo", firstTask.Name)
    58  	assert.Equal(t, "bar", firstTask.CallbackOnSuccess[0].Name)
    59  	assert.Equal(t, "qux", firstTask.CallbackOnSuccess[0].CallbackOnSuccess[0].Name)
    60  }