Skip to content

Commit

Permalink
adds the missing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ncode committed Apr 18, 2024
1 parent 282916f commit 93a664c
Showing 1 changed file with 62 additions and 4 deletions.
66 changes: 62 additions & 4 deletions pkg/aclmanager/aclmanager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,8 +221,11 @@ func TestSyncAcls(t *testing.T) {
expectedUpdated []string
listAclsError error
redisDoError error
saveAclError error
loadAclError error
wantSourceErr bool
wantDestinationErr bool
aclFile bool
}{
{
name: "ACLs synced with deletions",
Expand Down Expand Up @@ -274,6 +277,37 @@ func TestSyncAcls(t *testing.T) {
name: "Invalid aclManagerPrimary",
listAclsError: fmt.Errorf("error listing destination ACLs"),
},
{
name: "ACLs synced with deletions, aclFile",
sourceAcls: []interface{}{"user acl1", "user acl2"},
destinationAcls: []interface{}{"user acl1", "user acl3"},
expectedDeleted: []string{"acl3"},
expectedUpdated: []string{"acl2"},
aclFile: true,
},
{
name: "Error on save ACL file on primary, aclFile",
sourceAcls: []interface{}{"user acl1", "user acl2"},
saveAclError: fmt.Errorf("failed to save ACL on primary"),
aclFile: true,
wantSourceErr: true,
},
{
name: "Error on save ACL file on destination, aclFile",
sourceAcls: []interface{}{"user acl1", "user acl2"},
destinationAcls: []interface{}{"user acl1", "user acl3"},
saveAclError: fmt.Errorf("failed to save ACL on destination"),
aclFile: true,
wantDestinationErr: true,
},
{
name: "Error on load ACL file, aclFile",
sourceAcls: []interface{}{"user acl1", "user acl2"},
destinationAcls: []interface{}{"user acl1", "user acl3"},
loadAclError: fmt.Errorf("failed to load ACL"),
aclFile: true,
wantDestinationErr: true,
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -322,6 +356,30 @@ func TestSyncAcls(t *testing.T) {
}
}

if tt.listAclsError != nil && tt.wantDestinationErr {
destMock.ExpectDo("ACL", "LIST").SetErr(tt.listAclsError)
} else {
destMock.ExpectDo("ACL", "LIST").SetVal(tt.destinationAcls)
}

if tt.aclFile {
if tt.saveAclError != nil {
sourceMock.ExpectDo("ACL", "SAVE").SetErr(tt.saveAclError)
if !tt.wantSourceErr {
destMock.ExpectDo("ACL", "SAVE").SetErr(tt.saveAclError)
}
} else {
sourceMock.ExpectDo("ACL", "SAVE").SetVal("OK")
destMock.ExpectDo("ACL", "SAVE").SetVal("OK")
}

if tt.loadAclError != nil && !tt.wantSourceErr {
destMock.ExpectDo("ACL", "LOAD").SetErr(tt.loadAclError)
} else {
destMock.ExpectDo("ACL", "LOAD").SetVal("OK")
}
}

added, deleted, err := aclManagerFollower.SyncAcls(context.Background(), aclManagerPrimary)
if err != nil {
if tt.wantSourceErr {
Expand Down Expand Up @@ -531,7 +589,7 @@ func TestAclManager_Loop(t *testing.T) {
Addr: "localhost:6379",
Password: "password",
Username: "username",
aclfile: false,
aclFile: false,
nodes: make(map[string]int),
},
wantErr: false,
Expand All @@ -542,7 +600,7 @@ func TestAclManager_Loop(t *testing.T) {
Addr: "localhost:6379",
Password: "password",
Username: "username",
aclfile: false,
aclFile: false,
nodes: make(map[string]int),
},
wantErr: true,
Expand All @@ -554,7 +612,7 @@ func TestAclManager_Loop(t *testing.T) {
Addr: "localhost:6379",
Password: "password",
Username: "username",
aclfile: false,
aclFile: false,
nodes: make(map[string]int),
},
wantErr: true,
Expand All @@ -566,7 +624,7 @@ func TestAclManager_Loop(t *testing.T) {
Addr: "localhost:6379",
Password: "password",
Username: "username",
aclfile: false,
aclFile: false,
nodes: make(map[string]int),
},
wantErr: false,
Expand Down

0 comments on commit 93a664c

Please sign in to comment.