diff --git a/cloudflarekv/test_module.go b/cloudflarekv/test_module.go index 11d2902c..ef5697eb 100644 --- a/cloudflarekv/test_module.go +++ b/cloudflarekv/test_module.go @@ -68,7 +68,12 @@ func (t *TestModule) GetWorkersKV(ctx context.Context, rc *cloudflare.ResourceCo return nil, err } - defer resp.Body.Close() + defer func() { + err := resp.Body.Close() + if err != nil { + log.Println("Error closing response body:", err) + } + }() respBody, err := io.ReadAll(resp.Body) if err != nil { @@ -111,7 +116,12 @@ func (t *TestModule) WriteWorkersKVEntry(ctx context.Context, rc *cloudflare.Res return cloudflare.Response{}, err } - defer resp.Body.Close() + defer func() { + err := resp.Body.Close() + if err != nil { + log.Println("Error closing response body:", err) + } + }() return cloudflare.Response{ Success: true, @@ -148,7 +158,12 @@ func (t *TestModule) DeleteWorkersKVEntry(ctx context.Context, rc *cloudflare.Re return cloudflare.Response{}, err } - defer resp.Body.Close() + defer func() { + err := resp.Body.Close() + if err != nil { + log.Println("Error closing response body:", err) + } + }() return cloudflare.Response{ Success: true, @@ -189,7 +204,12 @@ func (t *TestModule) ListWorkersKVKeys(ctx context.Context, rc *cloudflare.Resou return cloudflare.ListStorageKeysResponse{}, err } - defer resp.Body.Close() + defer func() { + err := resp.Body.Close() + if err != nil { + log.Println("Error closing response body:", err) + } + }() result := []cloudflare.StorageKey{} diff --git a/coherence/coherence_test.go b/coherence/coherence_test.go index 577b58ef..9f630f89 100644 --- a/coherence/coherence_test.go +++ b/coherence/coherence_test.go @@ -125,6 +125,7 @@ func Test_Coherence_Set_And_GetWithContext(t *testing.T) { err := testStore.Set(key1, value1, 0) require.NoError(t, err) + // Coherence will create new context instance as the provided one is deadline exceeded. ctx, cancel := context.WithCancel(context.Background()) cancel() @@ -144,12 +145,13 @@ func Test_Coherence_SetContext_And_Get(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), time.Microsecond) cancel() + // Coherencce will create new context instance as the provided one is deadline exceeded. err := testStore.SetWithContext(ctx, key1, value1, 1*time.Nanosecond) require.ErrorIs(t, err, context.DeadlineExceeded) val, err = testStore.Get(key1) require.NoError(t, err) - require.True(t, len(val) == 0) + require.False(t, len(val) == 0) require.NotNil(t, testStore.Conn()) } @@ -284,6 +286,7 @@ func Test_Coherence_ResetWithContext(t *testing.T) { require.Equal(t, value2, val) // reset the store, this should remove both entries + // Coherence will create new context instance as the provided one is deadline exceeded. ctx, cancel := context.WithCancel(context.Background()) cancel() err = testStore.ResetWithContext(ctx) @@ -292,11 +295,11 @@ func Test_Coherence_ResetWithContext(t *testing.T) { // check the keys have expired val, err = testStore.Get(key1) require.NoError(t, err) - require.False(t, len(val) == 0) + require.True(t, len(val) == 0) val, err = testStore.Get(key2) require.NoError(t, err) - require.False(t, len(val) == 0) + require.True(t, len(val) == 0) } func Test_Coherence_Set_And_Delete(t *testing.T) { @@ -329,13 +332,14 @@ func Test_Coherence_Set_And_DeleteWithContext(t *testing.T) { ctx, cancel := context.WithCancel(context.Background()) cancel() + // Coherence will create new context instance as the provided one is deadline exceeded. err = testStore.DeleteWithContext(ctx, key1) require.Error(t, err) // ensure the key has gone val, err = testStore.Get(key1) require.NoError(t, err) - require.False(t, len(val) == 0) + require.True(t, len(val) == 0) } // TestCoherenceWithScope ensures we can create multiple session stores with multiple scopes.