mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-01-07 21:00:30 -06:00
Fix the settings metedata tests
This commit is contained in:
6
changelog/unreleased/fix-settings-metadata-tests.md
Normal file
6
changelog/unreleased/fix-settings-metadata-tests.md
Normal 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
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user