refactor: remove unused func/var/methods (#315)

Signed-off-by: Dhruv Jain <92215138+jaydee029@users.noreply.github.com>
This commit is contained in:
Dhruv Jain
2024-04-25 12:16:15 +05:30
committed by GitHub
parent d705c16ced
commit ca4e2c6131
29 changed files with 5 additions and 488 deletions
-3
View File
@@ -7,7 +7,6 @@ import (
"encoding/json"
"fmt"
"strings"
"sync"
"time"
"github.com/google/uuid"
@@ -39,8 +38,6 @@ import (
var _log = log.GetLogger()
var clusterNodeSyncMutexMap = make(map[string]*sync.Mutex)
const (
clusterNotifyChan = "cluster:notify"
)
-1
View File
@@ -14,7 +14,6 @@ import (
type relayAuditDatabaseService struct {
db *bun.DB
tag string
aps AccountPermissionService
}
func (ra *relayAuditDatabaseService) GetRelayAudit(ctx context.Context, req *v1.RelayAuditRequest) (res *v1.RelayAuditResponse, err error) {
-22
View File
@@ -26,28 +26,6 @@ func performRoleBasicChecks(t *testing.T, role *rolev3.Role, ruuid string) {
}
}
func performRoleBasicAuthzChecks(t *testing.T, mazc mockAuthzClient, ruuid string) {
if len(mazc.drpm) > 0 {
if mazc.drpm[len(mazc.drpm)-1].Role != "role-"+ruuid {
t.Errorf("incorrect role sent to authz; expected '%v' got '%v'", "role-"+ruuid, mazc.drpm[len(mazc.drpm)-1].Role)
}
}
if len(mazc.crpm) > 0 {
if len(mazc.crpm[len(mazc.crpm)-1].RolePermissionMappingList) != 1 {
t.Errorf("invalid number of roles sent to authz; expected 1, got '%v'", len(mazc.crpm[len(mazc.crpm)-1].RolePermissionMappingList))
}
if mazc.crpm[len(mazc.crpm)-1].RolePermissionMappingList[0].Role != "role-"+ruuid {
t.Errorf("incorrect role sent to authz; expected '%v' got '%v'", "role-"+ruuid, mazc.crpm[len(mazc.crpm)-1].RolePermissionMappingList[0].Role)
}
if len(mazc.crpm[len(mazc.crpm)-1].RolePermissionMappingList[0].Permission) != 1 {
t.Errorf("incorrect number of permissions sent to authz; expected '1', got '%v'", len(mazc.crpm[len(mazc.crpm)-1].RolePermissionMappingList[0].Permission))
}
if mazc.crpm[len(mazc.crpm)-1].RolePermissionMappingList[0].Permission[0] != "ops_star.all" {
t.Errorf("incorrect permissions sent to authz; expected 'ops_star.all', got '%v'", mazc.crpm[len(mazc.crpm)-1].RolePermissionMappingList[0].Permission[0])
}
}
}
func TestCreateRole(t *testing.T) {
db, mock := getDB(t)
defer db.Close()
-14
View File
@@ -12,20 +12,6 @@ import (
rolev3 "github.com/paralus/paralus/proto/types/rolepb/v3"
)
func performRolePermissionBasicChecks(t *testing.T, role *rolev3.RolePermission, ruuid string) {
_, err := uuid.Parse(role.GetMetadata().GetOrganization())
if err == nil {
t.Error("org in metadata should be name not id")
}
_, err = uuid.Parse(role.GetMetadata().GetPartner())
if err == nil {
t.Error("partner in metadata should be name not id")
}
if role.GetMetadata().GetId() != ruuid {
t.Error("invalid uuid returned")
}
}
func TestRolePermissionList(t *testing.T) {
db, mock := getDB(t)
defer db.Close()
-7
View File
@@ -153,13 +153,6 @@ func addUserGroupMappingsUpdateExpectation(mock sqlmock.Sqlmock, account string)
WithArgs().WillReturnRows(sqlmock.NewRows([]string{"id"}).AddRow(uuid.New().String()))
}
func addUserIdFetchExpectation(mock sqlmock.Sqlmock) string {
uid := uuid.New().String()
mock.ExpectQuery(`SELECT "identities"."id" FROM "identities" WHERE .*traits ->> 'email' = 'user-` + uid + `'`).
WithArgs().WillReturnRows(sqlmock.NewRows([]string{"id", "traits"}).AddRow(uid, []byte(`{"email":"user-`+uid+`", "first_name": "John", "last_name": "Doe", "description": "The OG user."}`)))
return uid
}
func addUserFetchExpectation(mock sqlmock.Sqlmock) string {
uid := uuid.New().String()
mock.ExpectQuery(`SELECT "identities"."id".* FROM "identities" WHERE .*traits ->> 'email' = 'user-` + uid + `'`).
-31
View File
@@ -28,37 +28,6 @@ func performUserBasicChecks(t *testing.T, user *userv3.User, uuuid string) {
}
}
func performUserBasicAuthzChecks(t *testing.T, mazc mockAuthzClient, uuuid string, roles []*userv3.ProjectNamespaceRole) {
if len(mazc.cp) > 0 {
for i, u := range mazc.cp[len(mazc.cp)-1].Policies {
if u.Sub != "u:user-"+uuuid {
t.Errorf("invalid sub in policy sent to authz; expected '%v', got '%v'", "u:user-"+uuuid, u.Sub)
}
if u.Obj != roles[i].Role {
t.Errorf("invalid obj in policy sent to authz; expected '%v', got '%v'", roles[i].Role, u.Obj)
}
if roles[i].Namespace != nil {
if u.Ns != fmt.Sprint(*roles[i].Namespace) {
t.Errorf("invalid ns in policy sent to authz; expected '%v', got '%v'", fmt.Sprint(roles[i].Namespace), u.Ns)
}
} else {
if u.Ns != "*" {
t.Errorf("invalid ns in policy sent to authz; expected '%v', got '%v'", "*", u.Ns)
}
}
if roles[i].Project != nil {
if u.Proj != *roles[i].Project {
t.Errorf("invalid proj in policy sent to authz; expected '%v', got '%v'", roles[i].Project, u.Proj)
}
} else {
if u.Proj != "*" {
t.Errorf("invalid proj in policy sent to authz; expected '%v', got '%v'", "*", u.Proj)
}
}
}
}
}
func TestCreateUser(t *testing.T) {
db, mock := getDB(t)
defer db.Close()