Exemple #1
0
func setUpWithCF(input string) (string, error) {
	var buildStruct DeployToCF
	err := yaml.Unmarshal([]byte(input), &buildStruct)
	if err != nil {
		return "", err
	}
	bf := buildfile.New()
	buildStruct.Deploy.Write(bf, nil)
	return bf.String(), err
}
Exemple #2
0
func setUpWithDrone(input string) (string, error) {
	var buildStruct PublishToDrone
	err := yaml.Unmarshal([]byte(input), &buildStruct)
	if err != nil {
		return "", err
	}
	bf := buildfile.New()
	buildStruct.Publish.Write(bf, &repo.Repo{Name: "name"})
	return bf.String(), err
}
Exemple #3
0
func TestWriteBuildScript(t *testing.T) {
	// temporary directory to store file
	dir, _ := ioutil.TempDir("", "drone-test-")
	defer os.RemoveAll(dir)

	b := Builder{}
	b.Build = &script.Build{
		Hosts: []string{"127.0.0.1"}}
	b.Key = []byte("ssh-rsa AAA...")
	b.Repo = &repo.Repo{
		Path:   "git://github.com/armab/drone.git",
		Branch: "master",
		Commit: "e7e046b35",
		PR:     "123",
		Dir:    "/var/cache/drone/github.com/armab/drone"}
	b.writeBuildScript(dir)

	// persist a dummy build script to disk
	script, err := ioutil.ReadFile(filepath.Join(dir, "drone"))
	if err != nil {
		t.Errorf("Expected id_rsa file saved to disk")
	}

	f := buildfile.New()
	f.WriteEnv("TERM", "xterm")
	f.WriteEnv("GOPATH", "/var/cache/drone")
	f.WriteEnv("SHELL", "/bin/bash")
	f.WriteEnv("CI", "true")
	f.WriteEnv("DRONE", "true")
	f.WriteEnv("DRONE_REMOTE", "git://github.com/armab/drone.git")
	f.WriteEnv("DRONE_BRANCH", "master")
	f.WriteEnv("DRONE_COMMIT", "e7e046b35")
	f.WriteEnv("DRONE_PR", "123")
	f.WriteEnv("DRONE_BUILD_DIR", "/var/cache/drone/github.com/armab/drone")
	f.WriteEnv("CI_NAME", "DRONE")
	f.WriteEnv("CI_BUILD_URL", "")
	f.WriteEnv("CI_REMOTE", "git://github.com/armab/drone.git")
	f.WriteEnv("CI_BRANCH", "master")
	f.WriteEnv("CI_PULL_REQUEST", "123")
	f.WriteHost("127.0.0.1")
	f.WriteFile("$HOME/.ssh/id_rsa", []byte("ssh-rsa AAA..."), 600)
	f.WriteCmd("git clone --depth=0 --recursive --branch=master git://github.com/armab/drone.git /var/cache/drone/github.com/armab/drone")
	f.WriteCmd("git fetch origin +refs/pull/123/head:refs/remotes/origin/pr/123")
	f.WriteCmd("git checkout -qf -b pr/123 origin/pr/123")

	if string(script) != f.String() {
		t.Errorf("Expected build script value saved as %s, got %s", f.String(), script)
	}
}