Skip to content

Commit

Permalink
Use require.Error in test instead of assert.Error to prevent nil poin…
Browse files Browse the repository at this point in the history
…ter 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.
  • Loading branch information
jhiemstrawisc committed Nov 26, 2024
1 parent 20fbc93 commit fe03cc4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion local_cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down

0 comments on commit fe03cc4

Please sign in to comment.