From 82b3d1106af7c7d9f24ad300c6db9cecf7e3e96b Mon Sep 17 00:00:00 2001 From: Ethan Koenig Date: Fri, 23 Dec 2016 00:02:46 -0500 Subject: [PATCH] Fix race condition in unit test --- modules/base/tool_test.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/modules/base/tool_test.go b/modules/base/tool_test.go index 9c4fb89e8e578..35995a9032795 100644 --- a/modules/base/tool_test.go +++ b/modules/base/tool_test.go @@ -76,14 +76,19 @@ func TestDetectEncoding(t *testing.T) { // iso-8859-1: dcor b = []byte{0x44, 0xe9, 0x63, 0x6f, 0x72, 0x0a} - testSuccess(b, "ISO-8859-1") + encoding, err := DetectEncoding(b) + assert.NoError(t, err) + // due to a race condition in `chardet` library, it could either detect + // "ISO-8859-1" or "IS0-8859-2" here. Technically either is correct, so + // we accept either. + assert.Contains(t, encoding, "ISO-8859") setting.Repository.AnsiCharset = "placeholder" testSuccess(b, "placeholder") // invalid bytes b = []byte{0xfa} - _, err := DetectEncoding(b) + _, err = DetectEncoding(b) assert.Error(t, err) }