示例#1
0
文件: config.go 项目: johnt337/gopack
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
}
示例#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.*")
	}
}
示例#3
0
func NewDependencyFromToml(tree *toml.TomlTree) (*Dependency, error) {
	var err error = nil
	var dep *Dependency

	dep, err = NewDependency(
		tree.GetDefault("import", "").(string),
		tree.GetDefault("url", "").(string),
		tree.GetDefault("version", "").(string),
	)
	if err != nil {
		return nil, err
	}
	dep.Type = tree.GetDefault("type", "").(string)
	dep.Branch = tree.GetDefault("branch", "").(string)
	dep.Tag = tree.GetDefault("tag", "").(string)

	return dep, nil
}