From 6a2a651bff9e772fe7a1d35721644d7115590cb0 Mon Sep 17 00:00:00 2001 From: kwall Date: Fri, 25 Nov 2022 10:45:49 +0000 Subject: [PATCH] use errors.Is when testing sarama errors This complies with changes from https://github.com/Shopify/sarama/pull/2131. This change ought to have been made when the upgrade to Sarama 1.33 was made, but it was overlooked. Its ommision hasn't caused a functional problem. Signed-off-by: kwall --- CHANGELOG.md | 1 + go.mod | 1 + go.sum | 1 + internal/services/topic.go | 7 ++++--- test/e2e_test.go | 3 ++- 5 files changed, 9 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6316616..a4c5598 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## 0.6.0 * Upgrade from go 1.13 to 1.19 +* Use errors.Is when testing Sarama errors. ## 0.5.0 diff --git a/go.mod b/go.mod index 9824821..d1f7869 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.19 require ( github.com/Shopify/sarama v1.35.0 github.com/golang/glog v1.0.0 + github.com/pkg/errors v0.9.1 github.com/prometheus/client_golang v1.12.1 github.com/xdg-go/scram v1.1.1 go.opentelemetry.io/contrib/instrumentation/github.com/Shopify/sarama/otelsarama v0.32.0 diff --git a/go.sum b/go.sum index be8eace..b490b1c 100644 --- a/go.sum +++ b/go.sum @@ -232,6 +232,7 @@ github.com/pierrec/lz4/v4 v4.1.15 h1:MO0/ucJhngq7299dKLwIMtgTfbkoSPF6AoMYDd8Q4q0 github.com/pierrec/lz4/v4 v4.1.15/go.mod h1:gZWDp/Ze/IJXGXf23ltt2EXimqmTUXEy0GFuRQyBid4= github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= +github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= diff --git a/internal/services/topic.go b/internal/services/topic.go index ea66c8f..313e8cb 100644 --- a/internal/services/topic.go +++ b/internal/services/topic.go @@ -7,6 +7,7 @@ package services import ( + "github.com/pkg/errors" "sort" "strconv" "time" @@ -144,7 +145,7 @@ func (ts *TopicService) reconcileTopic() (TopicReconcileResult, error) { } topicMetadata := metadata[0] - if topicMetadata.Err == sarama.ErrUnknownTopicOrPartition { + if errors.Is(topicMetadata.Err, sarama.ErrUnknownTopicOrPartition) { // canary topic doesn't exist, going to create it glog.V(1).Infof("The canary topic %s doesn't exist", topicMetadata.Name) @@ -166,7 +167,7 @@ func (ts *TopicService) reconcileTopic() (TopicReconcileResult, error) { // not creating the topic and returning error to avoid starting producer/consumer return result, &ErrExpectedClusterSize{} } - } else if topicMetadata.Err == sarama.ErrNoError { + } else if errors.Is(topicMetadata.Err, sarama.ErrNoError) { // canary topic already exists glog.V(1).Infof("The canary topic %s already exists", topicMetadata.Name) logTopicMetadata(topicMetadata) @@ -347,7 +348,7 @@ func (ts *TopicService) requestedAssignments(currentPartitions int, brokers []*s } else { index := 0 - for ;; { + for { again := false for _, rackName := range rackNames { diff --git a/test/e2e_test.go b/test/e2e_test.go index 40cc9e3..3b65fe6 100644 --- a/test/e2e_test.go +++ b/test/e2e_test.go @@ -9,6 +9,7 @@ package test import ( "context" + "github.com/pkg/errors" "io/ioutil" "log" "net/http" @@ -52,7 +53,7 @@ func TestCanaryTopicLiveness(t *testing.T) { topicMetadata := TopicMetadata[0] // topic haven't been created yet. - if topicMetadata.Err == sarama.ErrUnknownTopicOrPartition { + if errors.Is(topicMetadata.Err, sarama.ErrUnknownTopicOrPartition) { time.Sleep(time.Millisecond * 500) continue }