Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: go 1.21 compatibility #204

Merged
merged 1 commit into from
Sep 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions pkg/canrunner/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,19 @@ func TestRunMessageReceiver_NoMessages(t *testing.T) {
assert.Assert(t, errors.Is(canrunner.RunMessageReceiver(ctx, rx, node, clock), os.ErrClosed))
}

type contextCompareKeyType string

const contextCompareKey contextCompareKeyType = "sentinel-key"

func TestRunMessageReceiver_ReceiveMessage(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
rx := mockcanrunner.NewMockFrameReceiver(ctrl)
node := mockcanrunner.NewMockNode(ctrl)
clock := mockclock.NewMockClock(ctrl)
msg := mockcanrunner.NewMockReceivedMessage(ctrl)
ctx := context.Background()
const sentinel = "sentinel-value"
ctx := context.WithValue(context.Background(), contextCompareKey, sentinel)
// when the first receive succeeds
frame := can.Frame{ID: 42}
rx.EXPECT().Receive().Return(true)
Expand All @@ -48,8 +53,10 @@ func TestRunMessageReceiver_ReceiveMessage(t *testing.T) {
// and the node should be locked
node.EXPECT().Lock()
// and the message should be queried for a hook with the same context
// Comparing context is not well-defined, so we check for a sentinel value instead.
afterReceiveHook := func(c context.Context) error {
assert.DeepEqual(t, ctx, c)
value := c.Value(contextCompareKey)
assert.DeepEqual(t, value, sentinel)
return nil
}
msg.EXPECT().AfterReceiveHook().Return(afterReceiveHook)
Expand Down