Fix the settings metedata tests

This commit is contained in:
Roman Perekhod
2024-06-13 19:13:46 +02:00
parent e728c0b940
commit afd9ec67fe
5 changed files with 40 additions and 29 deletions

View File

@@ -0,0 +1,6 @@
Bugfix: Fix the settings metedata tests
We fix the settings metedata tests that had the data race
https://github.com/owncloud/ocis/pull/9341
https://github.com/owncloud/ocis/issues/9372

View File

@@ -21,11 +21,6 @@ var (
role1 = "11111111-1111-1111-1111-111111111111"
role2 = "22222222-2222-2222-2222-222222222222"
s = &Store{
Logger: logger,
l: &sync.Mutex{},
}
logger = olog.NewLogger(
olog.Color(true),
olog.Pretty(true),
@@ -93,17 +88,21 @@ var (
}
)
func init() {
s.cfg = defaults.DefaultConfig()
func initStore() *Store {
s := &Store{
Logger: logger,
l: &sync.Mutex{},
cfg: defaults.DefaultConfig(),
}
s.cfg.Commons = &shared.Commons{
AdminUserID: uuid.Must(uuid.NewV4()).String(),
}
_ = NewMDC(s)
setupRoles()
return s
}
func setupRoles() {
func setupRoles(s *Store) {
for i := range bundles {
if _, err := s.WriteBundle(bundles[i]); err != nil {
log.Fatal("error initializing ", err)
@@ -127,8 +126,9 @@ func TestAssignmentUniqueness(t *testing.T) {
}
for _, scenario := range scenarios {
scenario := scenario
t.Run(scenario.name, func(t *testing.T) {
s := initStore()
setupRoles(s)
firstAssignment, err := s.WriteRoleAssignment(scenario.userID, scenario.firstRole)
require.NoError(t, err)
require.Equal(t, firstAssignment.RoleId, scenario.firstRole)
@@ -159,12 +159,14 @@ func TestListRoleAssignmentByRole(t *testing.T) {
roleID string
}
var scenarios = map[string]struct {
var scenarios = []struct {
name string
assignments []assignment
queryRole string
numResults int
}{
"just 2 assignments": {
{
name: "just 2 assignments",
assignments: []assignment{
{
userID: einstein,
@@ -177,7 +179,8 @@ func TestListRoleAssignmentByRole(t *testing.T) {
queryRole: role1,
numResults: 2,
},
"no assignments match": {
{
name: "no assignments match",
assignments: []assignment{
{
userID: einstein,
@@ -190,7 +193,8 @@ func TestListRoleAssignmentByRole(t *testing.T) {
queryRole: role2,
numResults: 0,
},
"only one assignment matches": {
{
name: "only one assignment matches",
assignments: []assignment{
{
userID: einstein,
@@ -208,9 +212,10 @@ func TestListRoleAssignmentByRole(t *testing.T) {
},
}
for name, scenario := range scenarios {
scenario := scenario
t.Run(name, func(t *testing.T) {
for _, scenario := range scenarios {
t.Run(scenario.name, func(t *testing.T) {
s := initStore()
setupRoles(s)
for _, a := range scenario.assignments {
ass, err := s.WriteRoleAssignment(a.userID, a.roleID)
require.NoError(t, err)
@@ -226,6 +231,7 @@ func TestListRoleAssignmentByRole(t *testing.T) {
})
}
}
func TestDeleteAssignment(t *testing.T) {
var scenarios = []struct {
name string
@@ -242,8 +248,9 @@ func TestDeleteAssignment(t *testing.T) {
}
for _, scenario := range scenarios {
scenario := scenario
t.Run(scenario.name, func(t *testing.T) {
s := initStore()
setupRoles(s)
assignment, err := s.WriteRoleAssignment(scenario.userID, scenario.firstRole)
require.NoError(t, err)
require.Equal(t, assignment.RoleId, scenario.firstRole)

View File

@@ -138,6 +138,7 @@ var (
)
func TestBundles(t *testing.T) {
s := initStore()
for i := range bundleScenarios {
b := bundleScenarios[i]
t.Run(b.name, func(t *testing.T) {
@@ -178,17 +179,8 @@ func TestBundles(t *testing.T) {
}
func TestAppendSetting(t *testing.T) {
//mdc := NewMDC()
//s := Store{
//Logger: olog.NewLogger(
//olog.Color(true),
//olog.Pretty(true),
//olog.Level("info"),
//),
//l: &sync.Mutex{},
//mdc: mdc,
//}
s := initStore()
setupRoles(s)
// appending to non existing bundle creates new
_, err := s.AddSettingToBundle(appendTestBundleID, appendTestSetting1)

View File

@@ -8,6 +8,8 @@ import (
)
func TestPermission(t *testing.T) {
s := initStore()
setupRoles(s)
// bunldes are initialized within init func
p, err := s.ReadPermissionByID("readID", []string{"f36db5e6-a03c-40df-8413-711c67e40b47"})
require.NoError(t, err)

View File

@@ -64,6 +64,8 @@ func TestValues(t *testing.T) {
for i := range valueScenarios {
index := i
t.Run(valueScenarios[index].name, func(t *testing.T) {
s := initStore()
setupRoles(s)
value := valueScenarios[index].value
v, err := s.WriteValue(value)
require.NoError(t, err)
@@ -77,6 +79,8 @@ func TestValues(t *testing.T) {
}
func TestListValues(t *testing.T) {
s := initStore()
setupRoles(s)
for _, v := range valueScenarios {
_, err := s.WriteValue(v.value)
require.NoError(t, err)