-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Backport 5.0] No team cycles (#49621)
This change introduces a check on `UpdateTeam` to not introduce a circular parent relationship. The check effectively finds all teams that _are not descendants_ (so not in the subtree of) modified team, and looks whether the parent is there. It is only safe to set the parent team ID to a team outside of modified team's own descendants. ## Test plan * Testing database stores with Postgres. * Testing GraphQL API with fakes. <br> Backport da92373 from #49556 Co-authored-by: Cezary Bartoszuk <cezary.bartoszuk@sourcegraph.com>
- Loading branch information
1 parent
03cb237
commit 450824d
Showing
7 changed files
with
350 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package fakedb_test | ||
|
||
import ( | ||
"context" | ||
"sort" | ||
"testing" | ||
|
||
"github.com/google/go-cmp/cmp" | ||
|
||
"github.com/sourcegraph/sourcegraph/internal/database" | ||
"github.com/sourcegraph/sourcegraph/internal/database/fakedb" | ||
"github.com/sourcegraph/sourcegraph/internal/types" | ||
) | ||
|
||
func TestAncestors(t *testing.T) { | ||
fs := fakedb.New() | ||
eng := fs.AddTeam(&types.Team{Name: "eng"}) | ||
source := fs.AddTeam(&types.Team{Name: "source", ParentTeamID: eng}) | ||
_ = fs.AddTeam(&types.Team{Name: "repo-management", ParentTeamID: source}) | ||
sales := fs.AddTeam(&types.Team{Name: "sales"}) | ||
salesLeads := fs.AddTeam(&types.Team{Name: "sales-leads", ParentTeamID: sales}) | ||
ts, cursor, err := fs.TeamStore.ListTeams(context.Background(), database.ListTeamsOpts{ExceptAncestorID: source}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
if cursor != 0 { | ||
t.Fatal("non-zero cursor") | ||
} | ||
want := []*types.Team{ | ||
{ID: eng, Name: "eng"}, | ||
{ID: sales, Name: "sales"}, | ||
{ID: salesLeads, Name: "sales-leads", ParentTeamID: sales}, | ||
} | ||
sort.Slice(ts, func(i, j int) bool { return ts[i].ID < ts[j].ID }) | ||
sort.Slice(want, func(i, j int) bool { return want[i].ID < want[j].ID }) | ||
if diff := cmp.Diff(want, ts); diff != "" { | ||
t.Errorf("ListTeams{ExceptAncestorID} -want+got: %s", diff) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.