playing with an efficient file sync tool
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

60 lines
1.0 KiB

package main
import (
"bytes"
"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 := bytes.NewBuffer([]byte{})
if err := WriteConfig(buf, config); err != nil {
t.Fatal(err)
}
newConfig, err := ReadConfig(bytes.NewReader(buf.Bytes()))
if 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)
}
}
}
}