lib/config: Raw() -> RawCopy()
This commit is contained in:
committed by
Jakob Borg
parent
a1a91d5ef4
commit
f60b424d70
@@ -43,7 +43,7 @@ func (validationError) String() string {
|
||||
|
||||
func TestReplaceCommit(t *testing.T) {
|
||||
w := Wrap("/dev/null", Configuration{Version: 0})
|
||||
if w.Raw().Version != 0 {
|
||||
if w.RawCopy().Version != 0 {
|
||||
t.Fatal("Config incorrect")
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ func TestReplaceCommit(t *testing.T) {
|
||||
if w.RequiresRestart() {
|
||||
t.Fatal("Should not require restart")
|
||||
}
|
||||
if w.Raw().Version != CurrentVersion {
|
||||
if w.RawCopy().Version != CurrentVersion {
|
||||
t.Fatal("Config should have changed")
|
||||
}
|
||||
|
||||
@@ -76,7 +76,7 @@ func TestReplaceCommit(t *testing.T) {
|
||||
if !w.RequiresRestart() {
|
||||
t.Fatal("Should require restart")
|
||||
}
|
||||
if w.Raw().Version != CurrentVersion {
|
||||
if w.RawCopy().Version != CurrentVersion {
|
||||
t.Fatal("Config should have changed")
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ func TestReplaceCommit(t *testing.T) {
|
||||
if !w.RequiresRestart() {
|
||||
t.Fatal("Should still require restart")
|
||||
}
|
||||
if w.Raw().Version != CurrentVersion {
|
||||
if w.RawCopy().Version != CurrentVersion {
|
||||
t.Fatal("Config should not have changed")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,7 +456,7 @@ func TestNewSaveLoad(t *testing.T) {
|
||||
t.Error(err)
|
||||
}
|
||||
|
||||
if diff, equal := messagediff.PrettyDiff(cfg.Raw(), cfg2.Raw()); !equal {
|
||||
if diff, equal := messagediff.PrettyDiff(cfg.RawCopy(), cfg2.RawCopy()); !equal {
|
||||
t.Errorf("Configs are not equal. Diff:\n%s", diff)
|
||||
}
|
||||
|
||||
@@ -482,7 +482,7 @@ func TestCopy(t *testing.T) {
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
cfg := wrapper.Raw()
|
||||
cfg := wrapper.RawCopy()
|
||||
|
||||
bsOrig, err := json.MarshalIndent(cfg, "", " ")
|
||||
if err != nil {
|
||||
@@ -548,7 +548,7 @@ func TestPullOrder(t *testing.T) {
|
||||
// Serialize and deserialize again to verify it survives the transformation
|
||||
|
||||
buf := new(bytes.Buffer)
|
||||
cfg := wrapper.Raw()
|
||||
cfg := wrapper.RawCopy()
|
||||
cfg.WriteXML(buf)
|
||||
|
||||
t.Logf("%s", buf.Bytes())
|
||||
@@ -611,7 +611,7 @@ func TestDuplicateDevices(t *testing.T) {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
if l := len(wrapper.Raw().Devices); l != 3 {
|
||||
if l := len(wrapper.RawCopy().Devices); l != 3 {
|
||||
t.Errorf("Incorrect number of devices, %d != 3", l)
|
||||
}
|
||||
|
||||
@@ -755,7 +755,7 @@ func TestSharesRemovedOnDeviceRemoval(t *testing.T) {
|
||||
t.Errorf("Failed: %s", err)
|
||||
}
|
||||
|
||||
raw := wrapper.Raw()
|
||||
raw := wrapper.RawCopy()
|
||||
raw.Devices = raw.Devices[:len(raw.Devices)-1]
|
||||
|
||||
if len(raw.Folders[0].Devices) <= len(raw.Devices) {
|
||||
@@ -767,7 +767,7 @@ func TestSharesRemovedOnDeviceRemoval(t *testing.T) {
|
||||
t.Errorf("Failed: %s", err)
|
||||
}
|
||||
|
||||
raw = wrapper.Raw()
|
||||
raw = wrapper.RawCopy()
|
||||
if len(raw.Folders[0].Devices) > len(raw.Devices) {
|
||||
t.Error("Unexpected extra device")
|
||||
}
|
||||
|
||||
@@ -120,9 +120,11 @@ func (w *Wrapper) Unsubscribe(c Committer) {
|
||||
w.mut.Unlock()
|
||||
}
|
||||
|
||||
// Raw returns the currently wrapped Configuration object.
|
||||
func (w *Wrapper) Raw() Configuration {
|
||||
return w.cfg
|
||||
// RawCopy returns a copy of the currently wrapped Configuration object.
|
||||
func (w *Wrapper) RawCopy() Configuration {
|
||||
w.mut.Lock()
|
||||
defer w.mut.Unlock()
|
||||
return w.cfg.Copy()
|
||||
}
|
||||
|
||||
// Replace swaps the current configuration object for the given one.
|
||||
|
||||
Reference in New Issue
Block a user