Exemplo n.º 1
0
func addDepsTree(deps *Dependencies, depsTree *toml.TomlTree, modifiedChecksum bool, pos int) error {
	if depsTree == nil {
		return nil
	}
	for _, k := range depsTree.Keys() {

		depTree := depsTree.Get(k).(*toml.TomlTree)
		d := NewDependency(depTree.Get("import").(string))

		d.setScm(depTree)
		d.setSource(depTree)

		d.setCheckout(depTree, "branch", BranchFlag)
		d.setCheckout(depTree, "commit", CommitFlag)
		d.setCheckout(depTree, "tag", TagFlag)

		if err := d.Validate(); err != nil {
			return err
		}

		d.Fetch(modifiedChecksum)

		deps.Keys[pos] = k
		deps.Imports[pos] = d.Import
		deps.DepList[pos] = d

		pos++

		deps.ImportGraph.Insert(d)
	}
	return nil
}
Exemplo n.º 2
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.*")
	}
}