From 550ed51fee2efe5b5bf5cdb85db39253b56afbc3 Mon Sep 17 00:00:00 2001 From: aviau Date: Thu, 14 Jun 2018 15:39:14 -0400 Subject: [PATCH] openpgp: fix bad error message When failing, TestKeyExpiry would output the wrong expected key id. It would output "Expected key 1ABB25A0" instead of "Expected key 96A672F5". Avoid this mistake by declaring the variable only once and using it in the error format. Change-Id: I860d82bf2c7fa80558051cdb21a41d506e95c25f Reviewed-on: https://go-review.googlesource.com/118958 Reviewed-by: Filippo Valsorda Run-TryBot: Filippo Valsorda TryBot-Result: Gobot Gobot --- openpgp/keys_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/openpgp/keys_test.go b/openpgp/keys_test.go index 40aa391b..d877589a 100644 --- a/openpgp/keys_test.go +++ b/openpgp/keys_test.go @@ -29,16 +29,16 @@ func TestKeyExpiry(t *testing.T) { // // So this should select the newest, non-expired encryption key. key, _ := entity.encryptionKey(time1) - if id := key.PublicKey.KeyIdShortString(); id != "96A672F5" { - t.Errorf("Expected key 1ABB25A0 at time %s, but got key %s", time1.Format(timeFormat), id) + if id, expected := key.PublicKey.KeyIdShortString(), "96A672F5"; id != expected { + t.Errorf("Expected key %s at time %s, but got key %s", expected, time1.Format(timeFormat), id) } // Once the first encryption subkey has expired, the second should be // selected. time2, _ := time.Parse(timeFormat, "2013-07-09") key, _ = entity.encryptionKey(time2) - if id := key.PublicKey.KeyIdShortString(); id != "96A672F5" { - t.Errorf("Expected key 96A672F5 at time %s, but got key %s", time2.Format(timeFormat), id) + if id, expected := key.PublicKey.KeyIdShortString(), "96A672F5"; id != expected { + t.Errorf("Expected key %s at time %s, but got key %s", expected, time2.Format(timeFormat), id) } // Once all the keys have expired, nothing should be returned.