From 635795e16d720dd3cb73fae0a989cfcd52a14857 Mon Sep 17 00:00:00 2001 From: qmuntal Date: Thu, 13 Jul 2023 16:00:11 +0200 Subject: [PATCH] simplify some asserts --- statemachine_test.go | 8 +++----- states_test.go | 22 ++++++---------------- 2 files changed, 9 insertions(+), 21 deletions(-) diff --git a/statemachine_test.go b/statemachine_test.go index dce746b..f2f5c43 100644 --- a/statemachine_test.go +++ b/statemachine_test.go @@ -217,11 +217,9 @@ func TestStateMachine_PermittedTriggers_PermittedTriggersAreDistinctValues(t *te permitted, _ := sm.PermittedTriggers(context.Background()) - if got := len(permitted); got != 1 { - t.Fatalf("PermittedTriggers() = %v, want %v", got, 1) - } - if got := permitted[0]; got != triggerX { - t.Errorf("PermittedTriggers() = %v, want %v", got, triggerX) + want := []any{triggerX} + if !reflect.DeepEqual(permitted, want) { + t.Errorf("PermittedTriggers() = %v, want %v", permitted, want) } } diff --git a/states_test.go b/states_test.go index 312dc9f..6cd993d 100644 --- a/states_test.go +++ b/states_test.go @@ -296,14 +296,9 @@ func Test_stateRepresentation_Enter_ActionsExecuteInOrder(t *testing.T) { }) transition := Transition{Source: stateA, Destination: stateB, Trigger: triggerX} sr.Enter(context.Background(), transition) - if got := len(actual); got != 2 { - t.Fatalf("expected 2 actions to be executed, got %d", got) - } - if got := actual[0]; got != 0 { - t.Errorf("expected action 0 to be executed first, got %d", got) - } - if got := actual[1]; got != 1 { - t.Errorf("expected action 1 to be executed second, got %d", got) + want := []int{0, 1} + if !reflect.DeepEqual(actual, want) { + t.Errorf("expected %v, got %v", want, actual) } } @@ -466,14 +461,9 @@ func Test_stateRepresentation_Exit_ActionsExecuteInOrder(t *testing.T) { }) transition := Transition{Source: stateB, Destination: stateC, Trigger: triggerX} sr.Exit(context.Background(), transition) - if got := len(actual); got != 2 { - t.Fatalf("expected 2 actions to be executed, got %d", got) - } - if got := actual[0]; got != 0 { - t.Errorf("expected action 0 to be executed first, got %d", got) - } - if got := actual[1]; got != 1 { - t.Errorf("expected action 1 to be executed second, got %d", got) + want := []int{0, 1} + if !reflect.DeepEqual(actual, want) { + t.Errorf("expected %v, got %v", want, actual) } }