Skip to content

Commit

Permalink
use errors.Is when testing sarama errors
Browse files Browse the repository at this point in the history
This complies with changes from IBM/sarama#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 <[email protected]>
  • Loading branch information
k-wall committed Nov 25, 2022
1 parent c70e38d commit 6a2a651
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
7 changes: 4 additions & 3 deletions internal/services/topic.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
package services

import (
"github.com/pkg/errors"
"sort"
"strconv"
"time"
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -347,7 +348,7 @@ func (ts *TopicService) requestedAssignments(currentPartitions int, brokers []*s
} else {
index := 0

for ;; {
for {
again := false

for _, rackName := range rackNames {
Expand Down
3 changes: 2 additions & 1 deletion test/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package test

import (
"context"
"github.com/pkg/errors"
"io/ioutil"
"log"
"net/http"
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit 6a2a651

Please sign in to comment.