From 894bebdfc893b2ed85cdfdff3c49f90506cb9627 Mon Sep 17 00:00:00 2001 From: Jordan Orelli Date: Thu, 30 Jul 2020 14:25:27 +0000 Subject: [PATCH] paralell tests are easy too huh. --- examples/echo-server/server_test.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/examples/echo-server/server_test.go b/examples/echo-server/server_test.go index 354293a..fbeff2e 100644 --- a/examples/echo-server/server_test.go +++ b/examples/echo-server/server_test.go @@ -50,25 +50,31 @@ func (test *testRequest) Run(t *testing.T) { } func TestServer(t *testing.T) { - type series []testRequest + type list []testRequest - runSeries := func(node *tea.Tree, tests series) *tea.Tree { - for i, _ := range tests { + runSeries := func(node *tea.Tree, tests list) *tea.Tree { + for i := 0; i < len(tests); i++ { node = node.Child(&tests[i]) } return node } + runParallel := func(node *tea.Tree, tests list) { + for i := 0; i < len(tests); i++ { + node.Child(&tests[i]) + } + } + root := tea.New(&testStartServer{}) - runSeries(root, series{ + runSeries(root, list{ {path: "/users/alice", expect: 1}, {path: "/users/alice", expect: 2}, {path: "/users/alice", expect: 3}, {path: "/users/alice", expect: 4}, }) - runSeries(root, series{ + runSeries(root, list{ {path: "/users/alice", expect: 1}, {path: "/users/bob", expect: 1}, {path: "/users/alice", expect: 2}, @@ -76,5 +82,12 @@ func TestServer(t *testing.T) { {path: "/users/bob", expect: 2}, }) + runParallel(root, list{ + {path: "/users/alice", expect: 1}, + {path: "/users/alice", expect: 1}, + {path: "/users/alice", expect: 1}, + {path: "/users/alice", expect: 1}, + }) + tea.Run(t, root) }