github.com/QuangHoangHao/kafka-go@v0.4.36/error_test.go (about) 1 package kafka 2 3 import ( 4 "fmt" 5 "testing" 6 ) 7 8 func TestError(t *testing.T) { 9 errorCodes := []Error{ 10 Unknown, 11 OffsetOutOfRange, 12 InvalidMessage, 13 UnknownTopicOrPartition, 14 InvalidMessageSize, 15 LeaderNotAvailable, 16 NotLeaderForPartition, 17 RequestTimedOut, 18 BrokerNotAvailable, 19 ReplicaNotAvailable, 20 MessageSizeTooLarge, 21 StaleControllerEpoch, 22 OffsetMetadataTooLarge, 23 GroupLoadInProgress, 24 GroupCoordinatorNotAvailable, 25 NotCoordinatorForGroup, 26 InvalidTopic, 27 RecordListTooLarge, 28 NotEnoughReplicas, 29 NotEnoughReplicasAfterAppend, 30 InvalidRequiredAcks, 31 IllegalGeneration, 32 InconsistentGroupProtocol, 33 InvalidGroupId, 34 UnknownMemberId, 35 InvalidSessionTimeout, 36 RebalanceInProgress, 37 InvalidCommitOffsetSize, 38 TopicAuthorizationFailed, 39 GroupAuthorizationFailed, 40 ClusterAuthorizationFailed, 41 InvalidTimestamp, 42 UnsupportedSASLMechanism, 43 IllegalSASLState, 44 UnsupportedVersion, 45 TopicAlreadyExists, 46 InvalidPartitionNumber, 47 InvalidReplicationFactor, 48 InvalidReplicaAssignment, 49 InvalidConfiguration, 50 NotController, 51 InvalidRequest, 52 UnsupportedForMessageFormat, 53 PolicyViolation, 54 OutOfOrderSequenceNumber, 55 DuplicateSequenceNumber, 56 InvalidProducerEpoch, 57 InvalidTransactionState, 58 InvalidProducerIDMapping, 59 InvalidTransactionTimeout, 60 ConcurrentTransactions, 61 TransactionCoordinatorFenced, 62 TransactionalIDAuthorizationFailed, 63 SecurityDisabled, 64 BrokerAuthorizationFailed, 65 KafkaStorageError, 66 LogDirNotFound, 67 SASLAuthenticationFailed, 68 UnknownProducerId, 69 ReassignmentInProgress, 70 DelegationTokenAuthDisabled, 71 DelegationTokenNotFound, 72 DelegationTokenOwnerMismatch, 73 DelegationTokenRequestNotAllowed, 74 DelegationTokenAuthorizationFailed, 75 DelegationTokenExpired, 76 InvalidPrincipalType, 77 NonEmptyGroup, 78 GroupIdNotFound, 79 FetchSessionIDNotFound, 80 InvalidFetchSessionEpoch, 81 ListenerNotFound, 82 TopicDeletionDisabled, 83 FencedLeaderEpoch, 84 UnknownLeaderEpoch, 85 UnsupportedCompressionType, 86 } 87 88 for _, err := range errorCodes { 89 t.Run(fmt.Sprintf("verify that error %d has a non-empty title, description, and error message", err), func(t *testing.T) { 90 if len(err.Title()) == 0 { 91 t.Error("empty title") 92 } 93 if len(err.Description()) == 0 { 94 t.Error("empty description") 95 } 96 if len(err.Error()) == 0 { 97 t.Error("empty error message") 98 } 99 }) 100 } 101 102 t.Run("verify that an invalid error code has an empty title and description", func(t *testing.T) { 103 err := Error(-2) 104 105 if s := err.Title(); len(s) != 0 { 106 t.Error("non-empty title:", s) 107 } 108 109 if s := err.Description(); len(s) != 0 { 110 t.Error("non-empty description:", s) 111 } 112 }) 113 }