mirror of
https://github.com/octoleo/syncthing.git
synced 2024-12-23 11:28:59 +00:00
This commit is contained in:
parent
29cd156e71
commit
4faa5882f2
@ -9,6 +9,7 @@ package config
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"encoding/xml"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
@ -1180,3 +1181,36 @@ func load(path string, myID protocol.DeviceID) (Wrapper, error) {
|
|||||||
func wrap(path string, cfg Configuration) Wrapper {
|
func wrap(path string, cfg Configuration) Wrapper {
|
||||||
return Wrap(path, cfg, events.NoopLogger)
|
return Wrap(path, cfg, events.NoopLogger)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestInternalVersioningConfiguration(t *testing.T) {
|
||||||
|
// Verify that the versioning configuration XML seralizes to something
|
||||||
|
// reasonable.
|
||||||
|
|
||||||
|
cfg := New(device1)
|
||||||
|
cfg.Folders = append(cfg.Folders, NewFolderConfiguration(device1, "default", "default", fs.FilesystemTypeBasic, "/tmp"))
|
||||||
|
cfg.Folders[0].Versioning = VersioningConfiguration{
|
||||||
|
Type: "foo",
|
||||||
|
Params: map[string]string{"bar": "baz"},
|
||||||
|
CleanupIntervalS: 42,
|
||||||
|
}
|
||||||
|
|
||||||
|
// These things should all be present in the serialized version.
|
||||||
|
expected := []string{
|
||||||
|
`<versioning type="foo">`,
|
||||||
|
`<param key="bar" val="baz"`,
|
||||||
|
`<cleanupIntervalS>42<`,
|
||||||
|
`</versioning>`,
|
||||||
|
}
|
||||||
|
|
||||||
|
bs, err := xml.MarshalIndent(cfg, "", " ")
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, exp := range expected {
|
||||||
|
if !strings.Contains(string(bs), exp) {
|
||||||
|
t.Logf("%s", bs)
|
||||||
|
t.Fatal("bad serializion of versioning parameters")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -60,7 +60,11 @@ func (c *VersioningConfiguration) UnmarshalXML(d *xml.Decoder, start xml.StartEl
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *VersioningConfiguration) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
func (c *VersioningConfiguration) MarshalXML(e *xml.Encoder, start xml.StartElement) error {
|
||||||
return e.Encode(c.toInternal())
|
// Using EncodeElement instead of plain Encode ensures that we use the
|
||||||
|
// outer tag name from the VersioningConfiguration (i.e.,
|
||||||
|
// `<versioning>`) rather than whatever the internal representation
|
||||||
|
// would otherwise be.
|
||||||
|
return e.EncodeElement(c.toInternal(), start)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *VersioningConfiguration) toInternal() internalVersioningConfiguration {
|
func (c *VersioningConfiguration) toInternal() internalVersioningConfiguration {
|
||||||
|
Loading…
Reference in New Issue
Block a user