Skip to content

Commit

Permalink
chore: add balancer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Abdulsametileri committed Mar 29, 2024
1 parent aca1bc5 commit 38d1ee8
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
2 changes: 1 addition & 1 deletion balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ func GetBalancerReferenceHash() Balancer {
return &kafka.ReferenceHash{}
}

func GetBalancerRoundRobinh() Balancer {
func GetBalancerRoundRobin() Balancer {
return &kafka.RoundRobin{}
}
66 changes: 66 additions & 0 deletions balancer_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package kafka

import (
"reflect"
"testing"
)

func TestGetBalancerCRC32(t *testing.T) {
balancer := GetBalancerCRC32()
if balancer == nil {
t.Error("Expected non-nil balancer, got nil")
}
if reflect.TypeOf(balancer).String() != "*kafka.CRC32Balancer" {
t.Errorf("Expected *kafka.CRC32Balancer, got %s", reflect.TypeOf(balancer).String())
}
}

func TestGetBalancerHash(t *testing.T) {
balancer := GetBalancerHash()
if balancer == nil {
t.Error("Expected non-nil balancer, got nil")
}
if reflect.TypeOf(balancer).String() != "*kafka.Hash" {
t.Errorf("Expected *kafka.Hash, got %s", reflect.TypeOf(balancer).String())
}
}

func TestGetBalancerLeastBytes(t *testing.T) {
balancer := GetBalancerLeastBytes()
if balancer == nil {
t.Error("Expected non-nil balancer, got nil")
}
if reflect.TypeOf(balancer).String() != "*kafka.LeastBytes" {
t.Errorf("Expected *kafka.LeastBytes, got %s", reflect.TypeOf(balancer).String())
}
}

func TestGetBalancerMurmur2Balancer(t *testing.T) {
balancer := GetBalancerMurmur2Balancer()
if balancer == nil {
t.Error("Expected non-nil balancer, got nil")
}
if reflect.TypeOf(balancer).String() != "*kafka.Murmur2Balancer" {
t.Errorf("Expected *kafka.Murmur2Balancer, got %s", reflect.TypeOf(balancer).String())
}
}

func TestGetBalancerReferenceHash(t *testing.T) {
balancer := GetBalancerReferenceHash()
if balancer == nil {
t.Error("Expected non-nil balancer, got nil")
}
if reflect.TypeOf(balancer).String() != "*kafka.ReferenceHash" {
t.Errorf("Expected *kafka.ReferenceHash, got %s", reflect.TypeOf(balancer).String())
}
}

func TestGetBalancerRoundRobinh(t *testing.T) {
balancer := GetBalancerRoundRobin()
if balancer == nil {
t.Error("Expected non-nil balancer, got nil")
}
if reflect.TypeOf(balancer).String() != "*kafka.RoundRobin" {
t.Errorf("Expected *kafka.RoundRobin, got %s", reflect.TypeOf(balancer).String())
}
}

0 comments on commit 38d1ee8

Please sign in to comment.