toyohime/main_test.go
kare.nuorteva bf3ebf8d74 Replace config with a map
git-svn-id: file:///srv/svn/repo/toyohime/trunk@46 922d331f-388e-da47-97a9-ad700dc0b8b9
2017-05-07 15:36:23 +00:00

41 lines
1016 B
Go

package main
import (
"reflect"
"strings"
"testing"
"kkn.fi/cmd/vanity/internal"
)
func TestParseConfig(t *testing.T) {
config := `/gist git https://github.com/kare/gist
/vanity git https://github.com/kare/vanity
`
expected := map[string]*internal.Package{
"/gist": internal.NewPackage("/gist", "git", "https://github.com/kare/gist"),
"/vanity": internal.NewPackage("/vanity", "git", "https://github.com/kare/vanity"),
}
packages, err := readConfig(strings.NewReader(config))
if err != nil {
t.Fatalf("unexcepted configuration error: %v", err)
}
if len(packages) != 2 {
t.Fatalf("expecting config for %v packages, but got %v", 4, len(packages))
}
for key, pack := range expected {
if !reflect.DeepEqual(pack, packages[key]) {
t.Fatalf("expected %v but got %v", pack, packages[key])
}
}
}
func TestParseBrokenConfig(t *testing.T) {
config := "/gist git"
_, err := readConfig(strings.NewReader(config))
if err == nil {
t.Fatal("broken configuration did not return error")
}
}