示例#1
0
func TestLibResolveDeps(t *testing.T) {
	log.SetGlobalLogLevel(log.DEBUG)

	// construct a test for a basic resolver for type 'test'
	resolver := &Resolver{
		LibSources: map[string]LibSource{
			"test": &testSCM{},
		},
	}

	// dependency set for test
	testDeps := []*Dependency{
		&Dependency{
			Import:      "dependency1",
			VersionSpec: NewVersionSpec(OpEq, 1, 0, -1),
			Type:        "test",
		},
		&Dependency{
			Import:      "dependency2",
			Url:         url.MustParse("foo://somewhere.com/baz/gorf"),
			VersionSpec: NewVersionSpec(OpEq, 1, 0, -1),
		},
		&Dependency{
			Import:      "dependency3",
			Url:         url.MustParse("http://foobar.com/baz/gorf"),
			VersionSpec: NewVersionSpec(OpEq, 1, 0, -1),
		},
	}

	// target library set
	resolved := make(map[string]*Library)

	// create a pre-resolved entry
	dep := testDeps[0]
	resolved[dep.Import] = &Library{
		Version: &Version{1, 0, 0},
	}
	// test resolution
	if deps, err := resolver.LibResolveDeps(resolved, testDeps); err != nil {
		t.Errorf("%v", err)
	} else if len(deps) != 2 {
		t.Error("Expected 2 deps: got %v instead", len(deps))
	} else if deps[0].Import != testDeps[1].Import {
		t.Error("Result 0 should be %v not %v", testDeps[1].Import, deps[0].Import)
	} else if deps[1].Import != testDeps[2].Import {
		t.Error("Result 1 should be %v not %v", testDeps[2].Import, deps[1].Import)
	}
}
示例#2
0
func TestDeduplicateDeps(t *testing.T) {
	log.SetGlobalLogLevel(log.DEBUG)

	// construct a test for a basic resolver for type 'test'
	resolver := &Resolver{
		LibSources: map[string]LibSource{
			"test": &testSCM{},
		},
	}

	// dependency set for test
	testDeps := []*Dependency{
		&Dependency{
			Import:      "dependency1",
			VersionSpec: NewVersionSpec(OpEq, 1, 0, -1),
			Type:        "test",
		},
		&Dependency{
			Import:      "dependency2",
			Url:         url.MustParse("foo://somewhere.com/baz/gorf"),
			VersionSpec: NewVersionSpec(OpEq, 1, 0, -1),
		},
		&Dependency{
			Import:      "dependency3",
			Url:         url.MustParse("http://foobar.com/baz/gorf"),
			VersionSpec: NewVersionSpec(OpEq, 1, 0, -1),
		},
	}
	targetLen := len(testDeps)

	// ... duplicated
	testDeps = append(testDeps, testDeps...)

	// positive test
	results, err := resolver.DeduplicateDeps(testDeps)
	if err != nil {
		t.Errorf("%v", err)
	}
	if len(results) != targetLen {
		t.Errorf("Expected length of %v; got %v instead", targetLen, len(results))
	}
}
示例#3
0
// test standard rewrite rules
func TestRewrite(t *testing.T) {
	rules := RewriteRuleArray{}
	rules = append(rules, BasicRewriteRules...)
	rules = append(rules, GitRewriteRules...)

	for _, test := range []struct {
		Src *Dependency
		Dst *Dependency
	}{
		{
			Src: &Dependency{
				Import: "gopkg.in/foo/bar.v3",
			},
			Dst: &Dependency{
				Import: "gopkg.in/foo/bar.v3",
				Url:    url.MustParse("http://github.com/foo/bar"),
				Branch: "v3",
				Type:   "git",
			},
		}, {
			Src: &Dependency{
				Import: "gopkg.in/foo.v1",
			},
			Dst: &Dependency{
				Import: "gopkg.in/foo.v1",
				Url:    url.MustParse("http://github.com/go-foo/foo"),
				Branch: "v1",
				Type:   "git",
			},
		},
	} {
		if err := rules.Apply(test.Src); err != nil {
			t.Errorf("Error during replacement %v; Src: %v", err, test.Src.Flatten())
		}
		if !test.Src.Equal(test.Dst) {
			t.Errorf("Error during replacement Src: %#v; Dst: %#v",
				test.Src.Flatten(), test.Dst.Flatten())
		}
	}
}
示例#4
0
func TestResolver(t *testing.T) {
	log.SetGlobalLogLevel(log.DEBUG)

	// construct a test for a basic resolver for type 'test'
	resolver := &Resolver{
		LibSources: map[string]LibSource{
			"test": &testSCM{},
		},
	}

	// positive tests
	for ii, dep := range []*Dependency{
		&Dependency{
			Import:      "dependency1",
			VersionSpec: NewVersionSpec(OpEq, 1, 0, -1),
			Type:        "test",
		},
	} {
		if _, err := resolver.Resolve(dep); err != nil {
			t.Errorf("Error resolving dependency %v: %v", ii, err)
			t.Log("Dep: ", dep.Flatten())
		}
	}

	// negative tests
	for ii, dep := range []*Dependency{
		&Dependency{
			Import:      "dependency2",
			Url:         url.MustParse("foo://somewhere.com/baz/gorf"),
			VersionSpec: NewVersionSpec(OpEq, 1, 0, -1),
		},
	} {
		if _, err := resolver.Resolve(dep); err == nil {
			t.Errorf("Error ignoring dependency %v", ii)
			t.Log("Dep: ", dep.Flatten())
		}
	}
}