Skip to content

Commit

Permalink
adds new tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ncode committed Dec 4, 2023
1 parent 3db78b2 commit 8abd106
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions pkg/aclmanager/aclmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,22 +78,31 @@ func TestFindNodes(t *testing.T) {
},
wantErr: false,
},
{
name: "error on replicationInfo",
mockResp: followerOutput,
want: nil,
wantErr: true,
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
redisClient, mock := redismock.NewClientMock()

// Mocking the response for the Info function
mock.ExpectInfo("replication").SetVal(tt.mockResp)
if tt.wantErr {
mock.ExpectInfo("replication").SetErr(fmt.Errorf("error"))
} else {
mock.ExpectInfo("replication").SetVal(tt.mockResp)
}
aclManager := AclManager{RedisClient: redisClient}

nodes, err := aclManager.FindNodes()
if (err != nil) != tt.wantErr {
t.Errorf("FindNodes() error = %v, wantErr %v", err, tt.wantErr)
return
}

assert.Equal(t, tt.want, nodes)
})
}
Expand Down Expand Up @@ -281,6 +290,32 @@ func TestIsItPrimary(t *testing.T) {
}
}

func TestNewAclManager(t *testing.T) {
tests := []struct {
name string
want *AclManager
}{
{
name: "create AclManager",
want: &AclManager{
Addr: "localhost:6379",
Password: "password",
Username: "username",
},
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got := New(tt.want.Addr, tt.want.Username, tt.want.Password)
assert.Equal(t, tt.want.Addr, got.Addr)
assert.Equal(t, tt.want.Username, got.Username)
assert.Equal(t, tt.want.Password, got.Password)
assert.NotNil(t, got.RedisClient)
})
}
}

func BenchmarkParseRedisOutputFollower(b *testing.B) {
for i := 0; i < b.N; i++ {
_, err := parseRedisOutput(followerOutput)
Expand Down

0 comments on commit 8abd106

Please sign in to comment.