Beispiel #1
0
func tomlToMap(s string) (map[string]interface{}, error) {
	tree, err := toml.Load(s)

	if err != nil {
		return nil, err
	}

	return tree.ToMap(), nil

}
Beispiel #2
0
func HandleTOMLMetaData(datum []byte) (interface{}, error) {
	m := map[string]interface{}{}
	datum = removeTOMLIdentifier(datum)

	tree, err := toml.Load(string(datum))

	if err != nil {
		return m, err
	}

	m = tree.ToMap()

	return m, nil
}
Beispiel #3
0
func TestNewDependencyFromToml(t *testing.T) {
	var err error
	var tree *toml.TomlTree
	var dep *Dependency

	if tree, err = toml.Load(testDependencyEntry); err != nil {
		t.Errorf("Error parsing TOML data: %v", err)
	}
	name := "test_import"
	entry := tree.Get(name).(*toml.TomlTree)
	if dep, err = NewDependencyFromToml(entry); err != nil {
		t.Errorf("Error building dependency from TOML: %v", err)
	}
	if dep.Import != "foo/bar/baz" {
		t.Errorf("Bad value for import: '%v'. Expected: '%v'", dep.Import, "foo/bar/baz")
	}
	if dep.Type != "test" {
		t.Errorf("Bad value for test: '%v'. Expected: '%v'", dep.Type, "test")
	}
	if dep.Branch != "master" {
		t.Errorf("Bad value for master: '%v'. Expected: '%v'", dep.Branch, "master")
	}
	if dep.Tag != "release-1.0" {
		t.Errorf("Bad value for tag: '%v'. Expected: '%v'", dep.Tag, "release-1.0")
	}
	if dep.Url.String() != "http://github.com/foo/bar" {
		t.Errorf("Bad value for url: '%v'. Expected: '%v'",
			dep.Url.String(), "http://github.com/foo/bar")
	}
	if dep.VersionSpec.Major != 1 ||
		dep.VersionSpec.Minor != 0 ||
		dep.VersionSpec.Subminor != -1 {
		t.Errorf("Bad value for version: '%v'. Expected: '%v'",
			dep.VersionSpec.String(), "1.0.*")
	}
}