mirror of
https://github.com/jech/galene.git
synced 2024-11-22 08:35:57 +01:00
Clean up setting up of writable groups in tests.
The previous way depended on implementation details of GetConfiguration.
This commit is contained in:
parent
3ee5290b71
commit
da4a225e96
1 changed files with 27 additions and 9 deletions
|
@ -162,11 +162,29 @@ func TestUpgradeDescription(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNonWritableGroups(t *testing.T) {
|
func setupTest(dir, datadir string, writable bool) error {
|
||||||
Directory = t.TempDir()
|
Directory = dir
|
||||||
configuration.configuration = &Configuration{}
|
DataDirectory = datadir
|
||||||
|
f, err := os.Create(filepath.Join(datadir, "config.json"))
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer f.Close()
|
||||||
|
conf := `{}`
|
||||||
|
if writable {
|
||||||
|
conf = `{"writableGroups": true}`
|
||||||
|
}
|
||||||
|
_, err = f.WriteString(conf)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
_, err := GetDescription("test")
|
func TestNonWritableGroups(t *testing.T) {
|
||||||
|
err := setupTest(t.TempDir(), t.TempDir(), false)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("setupTest: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = GetDescription("test")
|
||||||
if !errors.Is(err, os.ErrNotExist) {
|
if !errors.Is(err, os.ErrNotExist) {
|
||||||
t.Errorf("GetDescription: got %#v, expected ErrNotExist", err)
|
t.Errorf("GetDescription: got %#v, expected ErrNotExist", err)
|
||||||
}
|
}
|
||||||
|
@ -179,12 +197,12 @@ func TestNonWritableGroups(t *testing.T) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestWritableGroups(t *testing.T) {
|
func TestWritableGroups(t *testing.T) {
|
||||||
Directory = t.TempDir()
|
err := setupTest(t.TempDir(), t.TempDir(), true)
|
||||||
configuration.configuration = &Configuration{
|
if err != nil {
|
||||||
WritableGroups: true,
|
t.Fatalf("setupTest: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := GetDescription("test")
|
_, err = GetDescription("test")
|
||||||
if !errors.Is(err, os.ErrNotExist) {
|
if !errors.Is(err, os.ErrNotExist) {
|
||||||
t.Errorf("GetDescription: got %v, expected ErrNotExist", err)
|
t.Errorf("GetDescription: got %v, expected ErrNotExist", err)
|
||||||
}
|
}
|
||||||
|
@ -197,7 +215,7 @@ func TestWritableGroups(t *testing.T) {
|
||||||
|
|
||||||
err = UpdateDescription("test", "", &Description{})
|
err = UpdateDescription("test", "", &Description{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Errorf("UpdateDescription: got %v", err)
|
t.Fatalf("UpdateDescription: got %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = GetDescription("test")
|
_, err = GetDescription("test")
|
||||||
|
|
Loading…
Reference in a new issue