mirror of
https://github.com/netbirdio/netbird.git
synced 2025-02-26 15:10:53 +01:00
Add benchmark tests to get account with claims (#2761)
* Add benchmark tests to get account with claims * add users to account objects * remove hardcoded env
This commit is contained in:
parent
baf0678ceb
commit
738387f2de
@ -982,6 +982,110 @@ func TestAccountManager_DeleteAccount(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func BenchmarkTest_GetAccountWithclaims(b *testing.B) {
|
||||||
|
claims := jwtclaims.AuthorizationClaims{
|
||||||
|
Domain: "example.com",
|
||||||
|
UserId: "pvt-domain-user",
|
||||||
|
DomainCategory: PrivateCategory,
|
||||||
|
}
|
||||||
|
|
||||||
|
publicClaims := jwtclaims.AuthorizationClaims{
|
||||||
|
Domain: "test.com",
|
||||||
|
UserId: "public-domain-user",
|
||||||
|
DomainCategory: PublicCategory,
|
||||||
|
}
|
||||||
|
|
||||||
|
am, err := createManager(b)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
id, err := am.getAccountIDWithAuthorizationClaims(context.Background(), claims)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
pid, err := am.getAccountIDWithAuthorizationClaims(context.Background(), publicClaims)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
users := genUsers("priv", 100)
|
||||||
|
|
||||||
|
acc, err := am.Store.GetAccount(context.Background(), id)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
acc.Users = users
|
||||||
|
|
||||||
|
err = am.Store.SaveAccount(context.Background(), acc)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
userP := genUsers("pub", 100)
|
||||||
|
|
||||||
|
pacc, err := am.Store.GetAccount(context.Background(), pid)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
pacc.Users = userP
|
||||||
|
|
||||||
|
err = am.Store.SaveAccount(context.Background(), pacc)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
b.Run("public without account ID", func(b *testing.B) {
|
||||||
|
//b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
_, err := am.getAccountIDWithAuthorizationClaims(context.Background(), publicClaims)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
b.Run("private without account ID", func(b *testing.B) {
|
||||||
|
//b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
_, err := am.getAccountIDWithAuthorizationClaims(context.Background(), claims)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
b.Run("private with account ID", func(b *testing.B) {
|
||||||
|
claims.AccountId = id
|
||||||
|
//b.ResetTimer()
|
||||||
|
for i := 0; i < b.N; i++ {
|
||||||
|
_, err := am.getAccountIDWithAuthorizationClaims(context.Background(), claims)
|
||||||
|
if err != nil {
|
||||||
|
b.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func genUsers(p string, n int) map[string]*User {
|
||||||
|
users := map[string]*User{}
|
||||||
|
now := time.Now()
|
||||||
|
for i := 0; i < n; i++ {
|
||||||
|
users[fmt.Sprintf("%s-%d", p, i)] = &User{
|
||||||
|
Id: fmt.Sprintf("%s-%d", p, i),
|
||||||
|
Role: UserRoleAdmin,
|
||||||
|
LastLogin: now,
|
||||||
|
CreatedAt: now,
|
||||||
|
Issued: "api",
|
||||||
|
AutoGroups: []string{"one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return users
|
||||||
|
}
|
||||||
|
|
||||||
func TestAccountManager_AddPeer(t *testing.T) {
|
func TestAccountManager_AddPeer(t *testing.T) {
|
||||||
manager, err := createManager(t)
|
manager, err := createManager(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user