Пример #1
0
func (s *S) TestPullRepository(c *gocheck.C) {
	p := testing.NewFakeProvisioner()
	p.PrepareOutput([]byte("pulled"))
	app := testing.NewFakeApp("your", "python", 1)
	out, err := fetch(p, app)
	c.Assert(err, gocheck.IsNil)
	c.Assert(string(out), gocheck.Equals, "pulled")
	path, _ := repository.GetPath()
	expectedCommand := fmt.Sprintf("cd %s && git fetch origin", path)
	c.Assert(p.GetCmds(expectedCommand, app), gocheck.HasLen, 1)
}
Пример #2
0
func (s *S) TestCheckout(c *gocheck.C) {
	p := testing.NewFakeProvisioner()
	p.PrepareOutput([]byte("updated"))
	app := testing.NewFakeApp("moon", "python", 1)
	out, err := checkout(p, app, "5734f0042844fdeb5bbc1b72b18f2dc1779cade7")
	c.Assert(err, gocheck.IsNil)
	c.Assert(out, gocheck.IsNil)
	path, _ := repository.GetPath()
	expectedCommand := fmt.Sprintf("cd %s && git checkout 5734f0042844fdeb5bbc1b72b18f2dc1779cade7", path)
	c.Assert(p.GetCmds(expectedCommand, app), gocheck.HasLen, 1)
}
Пример #3
0
// checkout updates the Git repository of the app to the given version.
func checkout(p provision.Provisioner, app provision.App, version string) ([]byte, error) {
	var buf bytes.Buffer
	path, err := repository.GetPath()
	if err != nil {
		return nil, fmt.Errorf("tsuru is misconfigured: %s", err)
	}
	cmd := fmt.Sprintf("cd %s && git checkout %s", path, version)
	if err := p.ExecuteCommand(&buf, &buf, app, cmd); err != nil {
		return buf.Bytes(), err
	}
	return nil, nil
}
Пример #4
0
// fetch runs a git fetch to update the code in the app.
//
// It works like Clone, fetching from the app remote repository.
func fetch(p provision.Provisioner, app provision.App) ([]byte, error) {
	var buf bytes.Buffer
	path, err := repository.GetPath()
	if err != nil {
		return nil, fmt.Errorf("tsuru is misconfigured: %s", err)
	}
	cmd := fmt.Sprintf("cd %s && git fetch origin", path)
	err = p.ExecuteCommand(&buf, &buf, app, cmd)
	b := buf.Bytes()
	log.Debugf(`"git fetch" output: %s`, b)
	return b, err
}
Пример #5
0
// Clone runs a git clone to clone the app repository in an app.
func clone(p provision.Provisioner, app provision.App) ([]byte, error) {
	var buf bytes.Buffer
	path, err := repository.GetPath()
	if err != nil {
		return nil, fmt.Errorf("tsuru is misconfigured: %s", err)
	}
	cmd := fmt.Sprintf("git clone %s %s --depth 1", repository.ReadOnlyURL(app.GetName()), path)
	err = p.ExecuteCommand(&buf, &buf, app, cmd)
	b := buf.Bytes()
	log.Debugf(`"git clone" output: %s`, b)
	return b, err
}
Пример #6
0
func (r *yamlHookRunner) loadConfig(app *App) error {
	if r.config != nil {
		return nil
	}
	repoPath, err := repository.GetPath()
	if err != nil {
		return err
	}
	err = r.loadConfigFromFile(app, path.Join(repoPath, "app.yaml"))
	if err != nil {
		err = r.loadConfigFromFile(app, path.Join(repoPath, "app.yml"))
	}
	return err
}
Пример #7
0
func (s *S) TestCloneRepository(c *gocheck.C) {
	h := &testing.TestHandler{}
	gandalfServer := testing.StartGandalfTestServer(h)
	defer gandalfServer.Close()
	p := testing.NewFakeProvisioner()
	p.PrepareOutput([]byte("something"))
	app := testing.NewFakeApp("your", "python", 1)
	out, err := clone(p, app)
	c.Assert(err, gocheck.IsNil)
	c.Assert(string(out), gocheck.Equals, "something")
	url := repository.ReadOnlyURL(app.GetName())
	path, _ := repository.GetPath()
	expectedCommand := fmt.Sprintf("git clone %s %s --depth 1", url, path)
	c.Assert(p.GetCmds(expectedCommand, app), gocheck.HasLen, 1)
}
Пример #8
0
func (s *S) TestDeploy(c *gocheck.C) {
	content := `{"git_url": "git://tsuruhost.com/cribcaged.git"}`
	h := &testing.TestHandler{Content: content}
	gandalfServer := testing.StartGandalfTestServer(h)
	defer gandalfServer.Close()
	provisioner := testing.NewFakeProvisioner()
	provisioner.PrepareOutput([]byte("cloned"))
	provisioner.PrepareOutput([]byte("updated"))
	app := testing.NewFakeApp("cribcaged", "python", 1)
	provisioner.Provision(app)
	w := &bytes.Buffer{}
	err := Git(provisioner, app, "5734f0042844fdeb5bbc1b72b18f2dc1779cade7", w)
	c.Assert(err, gocheck.IsNil)
	c.Assert(app.Commands, gocheck.DeepEquals, []string{"restart"})
	c.Assert(provisioner.InstalledDeps(app), gocheck.Equals, 1)
	cloneCommand := "git clone git://tsuruhost.com/cribcaged.git test/dir --depth 1"
	c.Assert(provisioner.GetCmds(cloneCommand, app), gocheck.HasLen, 1)
	path, _ := repository.GetPath()
	checkoutCommand := fmt.Sprintf("cd %s && git checkout 5734f0042844fdeb5bbc1b72b18f2dc1779cade7", path)
	c.Assert(provisioner.GetCmds(checkoutCommand, app), gocheck.HasLen, 1)
}