From fe03cc4ed0646768794672c5c0d2ac62cc69a4cf Mon Sep 17 00:00:00 2001 From: Justin Hiemstra Date: Tue, 26 Nov 2024 21:34:50 +0000 Subject: [PATCH] Use require.Error in test instead of assert.Error to prevent nil pointer deref Another issue fixed by a different commit exposed that failure to stop the test on this error generates a nil pointer dereference when we try to check the contents of a non-existent error. Using require.Error stops the test before reaching the dereference. --- local_cache/cache_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/local_cache/cache_test.go b/local_cache/cache_test.go index 04963cda7..5560f6d5a 100644 --- a/local_cache/cache_test.go +++ b/local_cache/cache_test.go @@ -330,7 +330,7 @@ func TestClient(t *testing.T) { _, err = client.DoGet(ctx, "pelican://"+param.Server_Hostname.GetString()+":"+strconv.Itoa(param.Server_WebPort.GetInt())+"/test/hello_world.txt.1", filepath.Join(tmpDir, "hello_world.txt.1"), false, client.WithToken(token), client.WithCaches(cacheUrl), client.WithAcquireToken(false)) - assert.Error(t, err) + require.Error(t, err) assert.Equal(t, "failed download from local-cache: server returned 404 Not Found", err.Error()) }) t.Cleanup(func() {