Skip to content

Commit

Permalink
chore: fix readme playground links
Browse files Browse the repository at this point in the history
  • Loading branch information
pancsta committed Jan 16, 2024
1 parent 4cd5922 commit a3f74a6
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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{
Expand Down
25 changes: 13 additions & 12 deletions examples/temporal-expense/expense_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
// --- PASS: TestExpense (2.00s)
// PASS

package temporal_expense
package main

import (
"context"
Expand All @@ -84,8 +84,6 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"

am "github.com/pancsta/asyncmachine-go/pkg/machine"
)

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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")
Expand All @@ -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
}

Expand All @@ -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
Expand Down Expand Up @@ -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())
Expand Down
10 changes: 6 additions & 4 deletions examples/temporal-fileprocessing/fileprocessing_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit a3f74a6

Please sign in to comment.