コード例 #1
0
ファイル: bench_test.go プロジェクト: emil2k/go-vcs
func BenchmarkFileSystem_GitGoGit(b *testing.B) {
	defer func() {
		b.StopTimer()
		b.StartTimer()
	}()

	cmds, files := makeGitCommandsAndFiles(benchFileSystemCommits)
	dir := initGitRepository(b, cmds...)
	r, err := git.Open(dir)
	if err != nil {
		b.Fatal(err)
	}

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		benchFileSystem(b, r, "mytag", files)
	}
}
コード例 #2
0
ファイル: bench_test.go プロジェクト: emil2k/go-vcs
func BenchmarkCommits_GitGoGit(b *testing.B) {
	defer func() {
		b.StopTimer()
		b.StartTimer()
	}()

	cmds, _ := makeGitCommandsAndFiles(benchCommitsCommits)
	openRepo := func() benchRepository {
		dir := initGitRepository(b, cmds...)
		r, err := git.Open(dir)
		if err != nil {
			b.Fatal(err)
		}
		return r
	}

	b.ResetTimer()
	for i := 0; i < b.N; i++ {
		benchCommits(b, openRepo, "mytag")
	}
}
コード例 #3
0
ファイル: ssh_test.go プロジェクト: emil2k/go-vcs
func TestRepository_UpdateEverything_ssh(t *testing.T) {
	t.Parallel()

	// TODO(sqs): this test has a lot of overlap with
	// TestRepository_UpdateEverything.

	gitCommands := []string{
		"GIT_COMMITTER_NAME=a [email protected] GIT_COMMITTER_DATE=2006-01-02T15:04:05Z git commit --allow-empty -m foo --author='a <*****@*****.**>' --date 2006-01-02T15:04:05Z",
	}
	// TODO(sqs): test hg ssh support when it's implemented
	tests := map[string]struct {
		vcs, baseDir, headDir string

		opener func(dir string) (vcs.Repository, error)
		cloner func(url, dir string, opt vcs.CloneOpt) (vcs.Repository, error)

		// newCmds should commit a file "newfile" in the repository
		// root and tag the commit with "second". This is used to test
		// that UpdateEverything picks up the new file from the
		// mirror's origin.
		newCmds []string

		wantUpdateResult *vcs.UpdateResult
	}{
		"git": { // git
			vcs: "git", baseDir: initGitRepository(t, gitCommands...), headDir: makeTmpDir(t, "git-update-ssh"),
			opener:  func(dir string) (vcs.Repository, error) { return git.Open(dir) },
			cloner:  func(url, dir string, opt vcs.CloneOpt) (vcs.Repository, error) { return git.Clone(url, dir, opt) },
			newCmds: []string{"git tag t0", "git checkout -b b0"},
			wantUpdateResult: &vcs.UpdateResult{
				Changes: []vcs.Change{
					{Op: vcs.NewOp, Branch: "b0"},
					{Op: vcs.NewOp, Branch: "t0"},
				},
			},
		},
		"git cmd": { // gitcmd
			vcs: "git", baseDir: initGitRepository(t, gitCommands...), headDir: makeTmpDir(t, "git-update-ssh"),
			opener:  func(dir string) (vcs.Repository, error) { return gitcmd.Open(dir) },
			cloner:  func(url, dir string, opt vcs.CloneOpt) (vcs.Repository, error) { return gitcmd.Clone(url, dir, opt) },
			newCmds: []string{"git tag t0", "git checkout -b b0"},
			wantUpdateResult: &vcs.UpdateResult{
				Changes: []vcs.Change{
					{Op: vcs.NewOp, Branch: "b0"},
					{Op: vcs.NewOp, Branch: "t0"},
				},
			},
		},
	}

	for label, test := range tests {
		func() {
			s, remoteOpts := startGitShellSSHServer(t, label, filepath.Dir(test.baseDir))
			defer s.Close()

			baseURL := s.GitURL + "/" + filepath.Base(test.baseDir)
			t.Logf("Cloning from %s to %s", baseURL, test.headDir)
			_, err := test.cloner(baseURL, test.headDir, vcs.CloneOpt{Bare: true, Mirror: true, RemoteOpts: remoteOpts})
			if err != nil {
				t.Errorf("Clone(%q, %q, %q): %s", label, baseURL, test.headDir, err)
				return
			}

			r, err := test.opener(test.headDir)
			if err != nil {
				t.Errorf("opener[->%s](%q): %s", reflect.TypeOf(test.opener).Out(0), test.headDir, err)
				return
			}

			// r should not have any tags yet.
			tags, err := r.Tags()
			if err != nil {
				t.Errorf("%s: Tags: %s", label, err)
				return
			}
			if len(tags) != 0 {
				t.Errorf("%s: got tags %v, want none", label, tags)
			}

			// run the newCmds to create the new file in the origin repository (NOT
			// the mirror repository; we want to test that UpdateEverything updates the
			// mirror repository).
			for _, cmd := range test.newCmds {
				c := exec.Command("bash", "-c", cmd)
				c.Dir = test.baseDir
				out, err := c.CombinedOutput()
				if err != nil {
					t.Fatalf("%s: exec `%s` failed: %s. Output was:\n\n%s", label, cmd, err, out)
				}
			}

			// update the mirror.
			result, err := r.(vcs.RemoteUpdater).UpdateEverything(remoteOpts)
			if err != nil {
				t.Errorf("%s: UpdateEverything: %s", label, err)
				return
			}
			if !reflect.DeepEqual(result, test.wantUpdateResult) {
				t.Errorf("%s: got UpdateResult == %v, want %v", label, asJSON(result), asJSON(test.wantUpdateResult))
			}

			// r should now have the tag t0 we added to the base repo,
			// since we just updated r.
			tags, err = r.Tags()
			if err != nil {
				t.Errorf("%s: Tags: %s", label, err)
				return
			}
			if got, want := tagNames(tags), []string{"t0"}; !reflect.DeepEqual(got, want) {
				t.Errorf("%s: got tags %v, want %v", label, got, want)
			}

			// r should now have the branch b0 we added to the base
			// repo, since we just updated r.
			branches, err := r.Branches(vcs.BranchesOptions{})
			if err != nil {
				t.Errorf("%s: Branches: %s", label, err)
				return
			}
			if got, want := branchNames(branches), []string{"b0", "master"}; !reflect.DeepEqual(got, want) {
				t.Errorf("%s: got branches %v, want %v", label, got, want)
			}
		}()
	}
}