Host set members (#301)
* Update host set member test * Add ListSetMembers method signature and doc * Move repository methods for host set members to new file * Add TestSetMembers * Implement ListSetMembers * Return hosts from ListSetMembers * Implement AddSetMembers * Implement DeleteSetMembers * Use sql.QueryContext not sql.Query * Implement SetSetMembers * Refactor: extract getHosts method * Refactor: extract createMembers method * Refactor: extract common functions * Return correct count of changed In SetSetMembers, retrieving the current list of hosts in the set happens after the transaction to modify the set has completed. This retrieval can result in an error but the number of modified rows is not effected. * Make list set members an unexported method * Get hosts within the same transaction as mutations of the set * Return hosts of set from LookupSet method * Return hosts of set from UpdateSet method * Remove listSetMembers * Fix merge conflict * Add NOTE and TODOs about using new pattern in "SetMembers" methods
This commit is contained in:
1 parent
39721047e4
commit
9ca8a4ec20
14 files changed
+1445
-88
No files matched your search
@@ -184,7 +184,7 @@ func (s Service) getFromRepo(ctx context.Context, id string) (*pb.HostSet, error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
h, err := repo.LookupSet(ctx, id)
|
||||
h, _, err := repo.LookupSet(ctx, id)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -241,7 +241,7 @@ func (s Service) updateInRepo(ctx context.Context, scopeId, catalogId, id string
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
out, rowsUpdated, err := repo.UpdateSet(ctx, scopeId, h, item.GetVersion(), dbMask)
|
||||
out, _, rowsUpdated, err := repo.UpdateSet(ctx, scopeId, h, item.GetVersion(), dbMask)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Unable to update host set: %v.", err)
|
||||
}
|
||||
@@ -288,7 +288,7 @@ func (s Service) addInRepo(ctx context.Context, scopeId, setId string, hostIds [
|
||||
// if err != nil {
|
||||
// return nil, status.Errorf(codes.Internal, "Unable to add members to group: %v.", err)
|
||||
// }
|
||||
out, err := repo.LookupSet(ctx, setId)
|
||||
out, _, err := repo.LookupSet(ctx, setId)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Unable to look up group: %v.", err)
|
||||
}
|
||||
@@ -308,7 +308,7 @@ func (s Service) setInRepo(ctx context.Context, scopeId, setId string, hostIds [
|
||||
// return nil, status.Errorf(codes.Internal, "Unable to set members on group: %v.", err)
|
||||
// }
|
||||
|
||||
out, err := repo.LookupSet(ctx, setId)
|
||||
out, _, err := repo.LookupSet(ctx, setId)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Unable to look up group: %v.", err)
|
||||
}
|
||||
@@ -327,7 +327,7 @@ func (s Service) removeInRepo(ctx context.Context, scopeId, setId string, hostId
|
||||
// if err != nil {
|
||||
// return nil, status.Errorf(codes.Internal, "Unable to remove members from group: %v.", err)
|
||||
// }
|
||||
out, err := repo.LookupSet(ctx, setId)
|
||||
out, _, err := repo.LookupSet(ctx, setId)
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "Unable to look up group: %v.", err)
|
||||
}
|
||||
|
||||
@@ -439,7 +439,7 @@ func TestUpdate(t *testing.T) {
|
||||
|
||||
resetHostSet := func() {
|
||||
version++
|
||||
_, _, err = repo.UpdateSet(context.Background(), proj.GetPublicId(), h, version, []string{"Name", "Description"})
|
||||
_, _, _, err = repo.UpdateSet(context.Background(), proj.GetPublicId(), h, version, []string{"Name", "Description"})
|
||||
require.NoError(t, err, "Failed to reset host.")
|
||||
version++
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user