diff --git a/README.md b/README.md index 02b90dc..22fcab1 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ AsyncMachine is a relational state machine which never blocks. ## Examples - [Expense Workflow](/examples/temporal-expense/expense_test.go) \| - [Temporal version](https://github.com/temporalio/samples-go/blob/main/expense/) \| [Go playground](https://goplay.tools/snippet/KAxlf3gm7pH) + [Temporal version](https://github.com/temporalio/samples-go/blob/main/expense/) \| [Go playground](https://play.golang.com/p/CqHX5dR7r_H) ```go am.States{ @@ -47,7 +47,7 @@ am.States{ ``` - [FileProcessing workflow](/examples/temporal-fileprocessing/fileprocessing.go) \| - [Temporal version](https://github.com/temporalio/samples-go/blob/main/fileprocessing/) \| [Go playground](https://goplay.tools/snippet/aTo4hsyJZck) + [Temporal version](https://github.com/temporalio/samples-go/blob/main/fileprocessing/) \| [Go playground](https://play.golang.com/p/TXMpqGFKUvM) ```go am.States{ diff --git a/examples/temporal-expense/expense_test.go b/examples/temporal-expense/expense_test.go index 28b0562..c063ebf 100644 --- a/examples/temporal-expense/expense_test.go +++ b/examples/temporal-expense/expense_test.go @@ -72,7 +72,7 @@ // --- PASS: TestExpense (2.00s) // PASS -package temporal_expense +package main import ( "context" @@ -84,8 +84,6 @@ import ( "testing" "time" - "github.com/stretchr/testify/assert" - am "github.com/pancsta/asyncmachine-go/pkg/machine" ) @@ -259,7 +257,7 @@ func ExpenseFlow( // WaitingForApproval is an automatic state } - // string(machine) == [Enabled, ExpenseCreated, WaitingForApproval] TODO + _ = machine.String() // (ExpenseCreated:1 WaitingForApproval:1) // WaitingForApproval to ApprovalGranted // Passes all new approval IDs to the machine, multiple times. @@ -289,8 +287,7 @@ func ExpenseFlow( } // PaymentInProgress is an automatic state, it will add itself at this point. - // string(machine) == - // [Enabled, ExpenseCreated, ApprovalGranted, PaymentInProgress] TODO + _ = machine.String() // (ExpenseCreated:1 ApprovalGranted:1 PaymentInProgress:1) // PaymentInProgress to PaymentCompleted log("waiting: PaymentInProgress to PaymentCompleted") @@ -300,8 +297,8 @@ func ExpenseFlow( case <-machine.When(am.S{"PaymentCompleted"}, nil): } - // string(machine) == - // [Enabled, ExpenseCreated, ApprovalGranted, PaymentCompleted] TODO + _ = machine.String() // (ExpenseCreated:1 ApprovalGranted:1 PaymentCompleted:1) + return machine, nil } @@ -314,12 +311,12 @@ func TestExpense(t *testing.T) { go func() { expenseId := <-expenseCh t.Log("approval request received: " + expenseId) - time.Sleep(1 * time.Second) + time.Sleep(10 * time.Millisecond) // approve a random ID t.Log("granting fake approval") approvalCh <- "fake" t.Log("sent fake approval") - time.Sleep(1 * time.Second) + time.Sleep(10 * time.Millisecond) // approve our ID t.Log("granting real approval") approvalCh <- expenseId @@ -357,8 +354,12 @@ func TestExpense(t *testing.T) { // start the flow and wait for the result machine, err := ExpenseFlow(context.Background(), t.Logf, approvalCh, "123") - assert.NoError(t, err) - assert.True(t, machine.Is(am.S{"PaymentCompleted"})) + if err != nil { + t.Fatal(err) + } + if !machine.Is(am.S{"PaymentCompleted"}) { + t.Fatal("not PaymentCompleted") + } // how it looks at the end t.Log("\n" + machine.String()) diff --git a/examples/temporal-fileprocessing/fileprocessing_test.go b/examples/temporal-fileprocessing/fileprocessing_test.go index 3c172ac..9837ff6 100644 --- a/examples/temporal-fileprocessing/fileprocessing_test.go +++ b/examples/temporal-fileprocessing/fileprocessing_test.go @@ -4,16 +4,18 @@ import ( "context" "testing" - "github.com/stretchr/testify/assert" - am "github.com/pancsta/asyncmachine-go/pkg/machine" ) func TestFileProcessing(t *testing.T) { // start the flow and wait for the result machine, err := FileProcessingFlow(context.Background(), t.Logf, "foo.txt") - assert.NoError(t, err) - assert.True(t, machine.Is(am.S{"FileUploaded"})) + if err != nil { + t.Fatal(err) + } + if !machine.Is(am.S{"FileUploaded"}) { + t.Fatal("not FileUploaded") + } // how it looks at the end t.Log("\n" + machine.String())