コード例 #1
0
ファイル: client.go プロジェクト: alexsaveliev/vcsstore
// Open implements vcsstore.Service and opens a repository. If the repository
// does not exist in the cluster, an os.ErrNotExist-satisfying error is
// returned.
func (c *Client) Open(vcsType string, cloneURL *url.URL) (interface{}, error) {
	key := vcsstore.EncodeRepositoryPath(vcsType, cloneURL)

	t, err := c.TransportForRepository(vcsType, cloneURL)
	if err != nil {
		return nil, err
	}

	vc := vcsclient.New(nil, &http.Client{Transport: t})
	repo, err := vc.Repository(vcsType, cloneURL)
	if err != nil {
		return nil, err
	}
	return &repository{c.datad, key, repo, t}, nil
}
コード例 #2
0
ファイル: lg_test.go プロジェクト: alexsaveliev/vcsstore
func testClone_lg(t *testing.T, repoPath string, opt *vcsclient.CloneInfo, wantCloneErrStr string, wantCloneErrHTTPStatus int) {
	storageDir, err := ioutil.TempDir("", "vcsstore-test")
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(storageDir)

	conf := &vcsstore.Config{
		StorageDir: storageDir,
		Log:        log.New(os.Stderr, "", 0),
		DebugLog:   log.New(os.Stderr, "", log.LstdFlags),
	}

	h := NewHandler(vcsstore.NewService(conf), NewGitTransporter(conf), nil)
	h.Log = log.New(os.Stderr, "", 0)
	h.Debug = true

	srv := httptest.NewServer(h)
	defer srv.Close()

	baseURL, err := url.Parse(srv.URL)
	if err != nil {
		t.Fatal(err)
	}
	c := vcsclient.New(baseURL, nil)
	repo, err := c.Repository(repoPath)
	if err != nil {
		t.Fatal(err)
	}

	if repo, ok := repo.(vcsclient.RepositoryCloneUpdater); ok {
		// Clones the first time.
		err := repo.CloneOrUpdate(opt)
		checkErr(t, err, wantCloneErrStr, wantCloneErrHTTPStatus)

		// Updates the second time.
		err = repo.CloneOrUpdate(opt)
		checkErr(t, err, wantCloneErrStr, wantCloneErrHTTPStatus)
	} else {
		t.Fatalf("Remote cloning is not implemented for %T.", repo)
	}
}
コード例 #3
0
ファイル: vcsstore.go プロジェクト: alexsaveliev/vcsstore
func cloneCmd(args []string) {
	fs := flag.NewFlagSet("clone", flag.ExitOnError)
	urlStr := fs.String("url", "http://localhost:"+defaultPort, "base URL to a running vcsstore API server")
	sshKeyFile := fs.String("i", "", "ssh private key file for clone remote")
	fs.Usage = func() {
		fmt.Fprintln(os.Stderr, `usage: vcsstore clone [options] repo-id vcs-type clone-url

Clones a repository on the server. Once finished, the repository will be
available to the client via the vcsstore API.

The options are:
`)
		fs.PrintDefaults()
		os.Exit(1)
	}
	fs.Parse(args)

	if fs.NArg() != 3 {
		fs.Usage()
	}

	baseURL, err := url.Parse(*urlStr)
	if err != nil {
		log.Fatal(err)
	}

	repoPath, vcsType := fs.Arg(0), fs.Arg(1)
	cloneURL, err := url.Parse(fs.Arg(2))
	if err != nil {
		log.Fatal(err)
	}

	var repo vcs.Repository
	c := vcsclient.New(baseURL, nil)
	repo, err = c.Repository(repoPath)
	if err != nil {
		log.Fatal("Open repository: ", err)
	}

	var opt vcs.RemoteOpts
	if *sshKeyFile != "" {
		key, err := ioutil.ReadFile(*sshKeyFile)
		if err != nil {
			log.Fatal(err)
		}
		opt.SSH = &vcs.SSHConfig{PrivateKey: key}
	}

	if repo, ok := repo.(vcsclient.RepositoryCloneUpdater); ok {
		err := repo.CloneOrUpdate(&vcsclient.CloneInfo{
			VCS: vcsType, CloneURL: cloneURL.String(), RemoteOpts: opt,
		})
		if err != nil {
			log.Fatal("Clone: ", err)
		}
	} else {
		log.Fatalf("Remote cloning is not implemented for %T.", repo)
	}

	fmt.Printf("%-5s cloned OK\n", repoPath)
}
コード例 #4
0
ファイル: diff_lg_test.go プロジェクト: alexsaveliev/vcsstore
func TestCrossRepoDiff_git_git_lg(t *testing.T) {
	t.Parallel()

	storageDir, err := ioutil.TempDir("", "vcsstore-test")
	if err != nil {
		t.Fatal(err)
	}
	defer os.RemoveAll(storageDir)

	conf := &vcsstore.Config{
		StorageDir: storageDir,
		Log:        log.New(os.Stderr, "", 0),
		DebugLog:   log.New(os.Stderr, "", log.LstdFlags),
	}

	h := NewHandler(vcsstore.NewService(conf), NewGitTransporter(conf), nil)
	h.Log = log.New(os.Stderr, "", 0)
	h.Debug = true

	srv := httptest.NewServer(h)
	defer srv.Close()

	baseURL, err := url.Parse(srv.URL)
	if err != nil {
		t.Fatal(err)
	}
	c := vcsclient.New(baseURL, nil)

	baseRepo := openAndCloneRepo(t, c, "github.com/sgtest/vcsstore-cross-repo-diff-test",
		&vcsclient.CloneInfo{VCS: "git", CloneURL: "https://github.com/sgtest/vcsstore-cross-repo-diff-test.git"})
	headRepo := openAndCloneRepo(t, c, "github.com/sqs/vcsstore-cross-repo-diff-test",
		&vcsclient.CloneInfo{VCS: "git", CloneURL: "https://github.com/sqs/vcsstore-cross-repo-diff-test.git"})

	const (
		baseCommit = "e7b2d6b444232fb1174fdd7561c25e94b0f62b60"
		headCommit = "843e1b8483f1542eeab08990b528608f5b318960"
	)
	want := &vcs.Diff{Raw: `diff --git f f
index 78981922613b2afb6025042ff6bd878ac1994e85..422c2b7ab3b3c668038da977e4e93a5fc623169c 100644
--- f
+++ f
@@ -1 +1,2 @@
 a
+b
`}

	// Run this a lot to ferret out concurrency issues.
	var n int
	envNumThreads := os.Getenv("TEST_CROSSREPO_DIFF_NUM_THREADS")
	if envNumThreads == "" {
		n = 5000
	} else {
		n, _ = strconv.Atoi(envNumThreads)
	}
	var wg sync.WaitGroup
	for i := 0; i < n; i++ {
		wg.Add(1)
		go func() {
			defer wg.Done()
			diff, err := baseRepo.(vcs.CrossRepoDiffer).CrossRepoDiff(baseCommit, headRepo, headCommit, nil)
			if err != nil {
				t.Fatal(err)
			}
			if !reflect.DeepEqual(diff, want) {
				t.Errorf("CrossRepoDiff: got %v, want %v", diff, want)
			}
		}()
	}
	wg.Wait()
}