浏览代码

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 <filippo@golang.org>
Run-TryBot: Filippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
aviau 7 年之前
父节点
当前提交
550ed51fee
共有 1 个文件被更改,包括 4 次插入4 次删除
  1. 4 4
      openpgp/keys_test.go

+ 4 - 4
openpgp/keys_test.go

@@ -29,16 +29,16 @@ func TestKeyExpiry(t *testing.T) {
 	//
 	//
 	// So this should select the newest, non-expired encryption key.
 	// So this should select the newest, non-expired encryption key.
 	key, _ := entity.encryptionKey(time1)
 	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
 	// Once the first encryption subkey has expired, the second should be
 	// selected.
 	// selected.
 	time2, _ := time.Parse(timeFormat, "2013-07-09")
 	time2, _ := time.Parse(timeFormat, "2013-07-09")
 	key, _ = entity.encryptionKey(time2)
 	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.
 	// Once all the keys have expired, nothing should be returned.