This repository has been archived on 2020-03-24. You can view files and clone it, but cannot push or open issues or pull requests.
SyncRefs/config_test.go

61 lines
1.0 KiB
Go

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)
}
}
}
}