From db4e2541bde4bcea636f7c572b6f9ca0a4305ad0 Mon Sep 17 00:00:00 2001 From: James Rasell Date: Mon, 24 May 2021 10:28:19 +0200 Subject: [PATCH] events: fix event endpoint tests to ignore heartbeats. seems when this PR was raised, the Nomad CI provider was having availability issues meaning the test suite was not correctly run, thus allowing broken tests into main. The PR itself exercised test code which had not been hit before. The particular problem is when identifying whether the event received is a heartbeat; this was performed using standard Golang conditionals. Unfortunately the operator == is not defined on byte arrays, resulting in the check always returning false. To overcome this issue the code now uses the bytes.Equal function to correctly compare the data. --- nomad/event_endpoint_test.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/nomad/event_endpoint_test.go b/nomad/event_endpoint_test.go index 804932534..a314444c9 100644 --- a/nomad/event_endpoint_test.go +++ b/nomad/event_endpoint_test.go @@ -1,6 +1,7 @@ package nomad import ( + "bytes" "context" "encoding/json" "fmt" @@ -96,7 +97,7 @@ OUTER: } // ignore heartbeat - if msg.Event == stream.JsonHeartbeat { + if bytes.Equal(msg.Event.Data, stream.JsonHeartbeat.Data) { continue } @@ -283,7 +284,7 @@ OUTER: t.Fatalf("Got error: %v", msg.Error.Error()) } - if msg.Event == stream.JsonHeartbeat { + if bytes.Equal(msg.Event.Data, stream.JsonHeartbeat.Data) { continue }