From 9bcfd4733a7ae7d12129b024e93536f7136e4a8e Mon Sep 17 00:00:00 2001 From: Stefan Majewsky Date: Tue, 21 Jul 2026 14:24:35 +0200 Subject: use t.Context() instead of context.TODO() in tests --- tests/container_test.go | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'tests/container_test.go') diff --git a/tests/container_test.go b/tests/container_test.go index 192487b..caa98d1 100644 --- a/tests/container_test.go +++ b/tests/container_test.go @@ -19,7 +19,6 @@ package tests import ( - "context" "fmt" "net/http" "testing" @@ -37,35 +36,35 @@ func TestContainerLifecycle(t *testing.T) { t.Errorf("expected c.Account() = %#v, got %#v instead\n", a, c.Account()) } - exists, err := c.Exists(context.TODO()) + exists, err := c.Exists(t.Context()) expectSuccess(t, err) expectBool(t, exists, false) - _, err = c.Headers(context.TODO()) + _, err = c.Headers(t.Context()) expectError(t, err, fmt.Sprintf("could not HEAD %q in Swift: expected 204 response, got 404 instead", containerName)) expectBool(t, schwift.Is(err, http.StatusNotFound), true) expectBool(t, schwift.Is(err, http.StatusNoContent), false) // DELETE should be idempotent and not return success on non-existence, but // OpenStack LOVES to be inconsistent with everything (including, notably, itself) - err = c.Delete(context.TODO(), nil) + err = c.Delete(t.Context(), nil) expectError(t, err, fmt.Sprintf("could not DELETE %q in Swift: expected 204 response, got 404 instead:

Not Found

The resource could not be found.

", containerName)) - err = c.Create(context.TODO(), nil) + err = c.Create(t.Context(), nil) expectSuccess(t, err) - exists, err = c.Exists(context.TODO()) + exists, err = c.Exists(t.Context()) expectSuccess(t, err) expectBool(t, exists, true) - err = c.Delete(context.TODO(), nil) + err = c.Delete(t.Context(), nil) expectSuccess(t, err) }) } func TestContainerUpdate(t *testing.T) { testWithContainer(t, func(c *schwift.Container) { - hdr, err := c.Headers(context.TODO()) + hdr, err := c.Headers(t.Context()) expectSuccess(t, err) expectBool(t, hdr.ObjectCount().Exists(), true) expectUint64(t, hdr.ObjectCount().Get(), 0) @@ -74,10 +73,10 @@ func TestContainerUpdate(t *testing.T) { hdr.ObjectCountQuota().Set(23) hdr.BytesUsedQuota().Set(42) - err = c.Update(context.TODO(), hdr, nil) + err = c.Update(t.Context(), hdr, nil) expectSuccess(t, err) - hdr, err = c.Headers(context.TODO()) + hdr, err = c.Headers(t.Context()) expectSuccess(t, err) expectUint64(t, hdr.BytesUsedQuota().Get(), 42) expectUint64(t, hdr.ObjectCountQuota().Get(), 23) @@ -87,7 +86,7 @@ func TestContainerUpdate(t *testing.T) { func expectContainerExistence(t *testing.T, c *schwift.Container, expectedExists bool) { t.Helper() c.Invalidate() - actualExists, err := c.Exists(context.TODO()) + actualExists, err := c.Exists(t.Context()) expectSuccess(t, err) expectBool(t, actualExists, expectedExists) } -- cgit v1.3.1