From 47998d1ee6489fd4753eba3a5944826f06b0bb2e Mon Sep 17 00:00:00 2001 From: "tao.yang" Date: Mon, 4 Sep 2023 16:59:23 +0800 Subject: [PATCH] cleanup: omit comparison with bool constants Signed-off-by: tao.yang Kubernetes-commit: b35357b6c08f21ba0fd312536051394c2567ec79 --- pkg/server/egressselector/config_test.go | 4 ++-- pkg/server/options/tracing_test.go | 4 ++-- pkg/storage/cacher/cache_watcher_test.go | 2 +- pkg/storage/cacher/cacher.go | 6 +++--- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/pkg/server/egressselector/config_test.go b/pkg/server/egressselector/config_test.go index 2b9861ae9..6effe442c 100644 --- a/pkg/server/egressselector/config_test.go +++ b/pkg/server/egressselector/config_test.go @@ -541,9 +541,9 @@ func TestValidateEgressSelectorConfiguration(t *testing.T) { for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { errs := ValidateEgressSelectorConfiguration(tc.contents) - if tc.expectError == false && len(errs) != 0 { + if !tc.expectError && len(errs) != 0 { t.Errorf("Calling ValidateEgressSelectorConfiguration expected no error, got %v", errs) - } else if tc.expectError == true && len(errs) == 0 { + } else if tc.expectError && len(errs) == 0 { t.Errorf("Calling ValidateEgressSelectorConfiguration expected error, got no error") } }) diff --git a/pkg/server/options/tracing_test.go b/pkg/server/options/tracing_test.go index d05c08e54..1d29cce52 100644 --- a/pkg/server/options/tracing_test.go +++ b/pkg/server/options/tracing_test.go @@ -67,9 +67,9 @@ func TestValidateTracingOptions(t *testing.T) { for _, tc := range testcases { t.Run(tc.name, func(t *testing.T) { errs := tc.contents.Validate() - if tc.expectError == false && len(errs) != 0 { + if !tc.expectError && len(errs) != 0 { t.Errorf("Calling Validate expected no error, got %v", errs) - } else if tc.expectError == true && len(errs) == 0 { + } else if tc.expectError && len(errs) == 0 { t.Errorf("Calling Validate expected error, got no error") } }) diff --git a/pkg/storage/cacher/cache_watcher_test.go b/pkg/storage/cacher/cache_watcher_test.go index b47fe0ed4..1a59615ce 100644 --- a/pkg/storage/cacher/cache_watcher_test.go +++ b/pkg/storage/cacher/cache_watcher_test.go @@ -485,7 +485,7 @@ func TestCacheWatcherDrainingNoBookmarkAfterResourceVersionReceived(t *testing.T forget := func(drainWatcher bool) { lock.Lock() defer lock.Unlock() - if drainWatcher == true { + if drainWatcher { t.Fatalf("didn't expect drainWatcher to be set to true") } count++ diff --git a/pkg/storage/cacher/cacher.go b/pkg/storage/cacher/cacher.go index 7248fe717..c7d9390ae 100644 --- a/pkg/storage/cacher/cacher.go +++ b/pkg/storage/cacher/cacher.go @@ -1252,7 +1252,7 @@ func (c *Cacher) LastSyncResourceVersion() (uint64, error) { // // The returned function must be called under the watchCache lock. func (c *Cacher) getBookmarkAfterResourceVersionLockedFunc(ctx context.Context, parsedResourceVersion uint64, opts storage.ListOptions) (func() uint64, error) { - if opts.SendInitialEvents == nil || *opts.SendInitialEvents == false || !opts.Predicate.AllowWatchBookmarks { + if opts.SendInitialEvents == nil || !*opts.SendInitialEvents || !opts.Predicate.AllowWatchBookmarks { return func() uint64 { return 0 }, nil } return c.getCommonResourceVersionLockedFunc(ctx, parsedResourceVersion, opts) @@ -1267,7 +1267,7 @@ func (c *Cacher) getBookmarkAfterResourceVersionLockedFunc(ctx context.Context, // // The returned function must be called under the watchCache lock. func (c *Cacher) getStartResourceVersionForWatchLockedFunc(ctx context.Context, parsedWatchResourceVersion uint64, opts storage.ListOptions) (func() uint64, error) { - if opts.SendInitialEvents == nil || *opts.SendInitialEvents == true { + if opts.SendInitialEvents == nil || *opts.SendInitialEvents { return func() uint64 { return parsedWatchResourceVersion }, nil } return c.getCommonResourceVersionLockedFunc(ctx, parsedWatchResourceVersion, opts) @@ -1298,7 +1298,7 @@ func (c *Cacher) getCommonResourceVersionLockedFunc(ctx context.Context, parsedW // Additionally, it instructs the caller whether it should ask for // all events from the cache (full state) or not. func (c *Cacher) waitUntilWatchCacheFreshAndForceAllEvents(ctx context.Context, requestedWatchRV uint64, opts storage.ListOptions) (bool, error) { - if opts.SendInitialEvents != nil && *opts.SendInitialEvents == true { + if opts.SendInitialEvents != nil && *opts.SendInitialEvents { err := c.watchCache.waitUntilFreshAndBlock(ctx, requestedWatchRV) defer c.watchCache.RUnlock() return err == nil, err