diff --git a/config.go b/config.go new file mode 100644 index 0000000..d772b96 --- /dev/null +++ b/config.go @@ -0,0 +1,24 @@ +package main + +import "encoding/xml" + +type Config struct { + XMLName xml.Name `xml:"config"` + SyncRefs []SyncRef `xml:"refs>ref"` + Groups []Group `xml:"groups>group"` +} + +type Group struct { + XMLName xml.Name `xml:"group"` + ID string `xml:"id,attr"` + Active bool `xml:"active,attr"` + Contains []string `xml:"contains>refID"` +} + +type SyncRef struct { + XMLName xml.Name `xml:"ref"` + ID string `xml:"id,attr"` + URI string + ReadOnly bool + Deletes bool +} diff --git a/config_test.go b/config_test.go new file mode 100644 index 0000000..f0043eb --- /dev/null +++ b/config_test.go @@ -0,0 +1,60 @@ +package main + +import ( + "encoding/xml" + "net/url" + "testing" + + uuid "github.com/satori/go.uuid" +) + +func TestConfig(t *testing.T) { + + u, err := url.Parse("file:///tmp/tmp.xJiSJUcyus") + if err != nil { + t.Fatal(err) + } + so1 := SyncRef{ + ID: uuid.NewV4().String(), + URI: u.String(), + } + so2 := SyncRef{ + ID: uuid.NewV4().String(), + URI: "file:///tmp/tmp.bhSM7oRner", + } + config := Config{ + SyncRefs: []SyncRef{ + so1, + so2, + }, + Groups: []Group{ + Group{ + ID: uuid.NewV4().String(), + Contains: []string{so1.ID, so2.ID}, + }, + }, + } + buf, err := xml.MarshalIndent(config, "", " ") + if err != nil { + t.Fatal(err) + } + + newConfig := Config{} + if err := xml.Unmarshal(buf, &newConfig); err != nil { + t.Fatal(err) + } + + for _, group := range newConfig.Groups { + for _, contain := range group.Contains { + found := false + for _, ref := range newConfig.SyncRefs { + if ref.ID == contain { + found = true + } + } + if !found { + t.Errorf("expected all group ref IDs to exist, but %q did not", contain) + } + } + } +}