grim/convey

closing merged branch
expand-list
2017-10-03, Gary Kramlich
345a52ef04c6
closing merged branch
/*
* Convey
* Copyright 2016-2017 Gary Kramlich <grim@reaperworld.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package bitbucket
import (
"github.com/aphistic/sweet"
. "github.com/onsi/gomega"
"bitbucket.org/rw_grim/convey/config"
"bitbucket.org/rw_grim/convey/docker"
"bitbucket.org/rw_grim/convey/plans"
"bitbucket.org/rw_grim/convey/stages"
"bitbucket.org/rw_grim/convey/tasks"
)
func (b *bitbucketSuite) TestLoaderSimple(t sweet.T) {
l := Loader{}
data := []byte(`image: python:3
pipelines:
default:
- step:
script:
- set -ex
- find . -type f -iname "*.pyc" -exec rm -f {} \; || true
- find . -type d -iname __pycache__ -exec rm -rf {} \; || true
- pip install -r dev-requirements.txt
- flake8
- PYTHONPATH=$(pwd) py.test --color=auto --cov=pipelines --cov-report=term-missing tests`)
cfg, err := l.Load("", "", data)
Expect(err).To(BeNil())
expected := &config.Config{
Tasks: map[string]tasks.Task{
"import": &docker.Import{
Files: []string{"."},
},
"default-step-0-0": &docker.Run{
Image: "python:3",
WorkDir: "/workspace",
Script: []string{
"set -ex",
"find . -type f -iname \"*.pyc\" -exec rm -f {} \\; || true",
"find . -type d -iname __pycache__ -exec rm -rf {} \\; || true",
"pip install -r dev-requirements.txt",
"flake8",
"PYTHONPATH=$(pwd) py.test --color=auto --cov=pipelines --cov-report=term-missing tests",
},
Shell: "/bin/sh",
},
},
Plans: map[string]plans.Plan{
"default": {
Stages: []stages.Stage{
stages.Stage{
Name: "stage-0",
Enabled: true,
Concurrent: false,
Run: "on-success",
Environment: nil,
Tasks: []string{"import", "default-step-0-0"},
},
},
},
},
}
Expect(cfg).To(Equal(expected))
}
func (b *bitbucketSuite) TestLoaderComplexGlobalImage(t sweet.T) {
l := Loader{}
data := []byte(`image:
name: python:3
pipelines:
default:
- step:
script:
- set -ex
- find . -type f -iname "*.pyc" -exec rm -f {} \; || true
- find . -type d -iname __pycache__ -exec rm -rf {} \; || true
- pip install -r dev-requirements.txt
- flake8
- PYTHONPATH=$(pwd) py.test --color=auto --cov=pipelines --cov-report=term-missing tests`)
cfg, err := l.Load("", "", data)
Expect(err).To(BeNil())
expected := &config.Config{
Tasks: map[string]tasks.Task{
"import": &docker.Import{
Files: []string{"."},
},
"default-step-0-0": &docker.Run{
Image: "python:3",
WorkDir: "/workspace",
Script: []string{
"set -ex",
"find . -type f -iname \"*.pyc\" -exec rm -f {} \\; || true",
"find . -type d -iname __pycache__ -exec rm -rf {} \\; || true",
"pip install -r dev-requirements.txt",
"flake8",
"PYTHONPATH=$(pwd) py.test --color=auto --cov=pipelines --cov-report=term-missing tests",
},
Shell: "/bin/sh",
},
},
Plans: map[string]plans.Plan{
"default": {
Stages: []stages.Stage{
stages.Stage{
Name: "stage-0",
Enabled: true,
Concurrent: false,
Run: "on-success",
Environment: nil,
Tasks: []string{"import", "default-step-0-0"},
},
},
},
},
}
Expect(cfg).To(Equal(expected))
}
func (b *bitbucketSuite) TestLoaderComplexGlobalImageWithLogin(t sweet.T) {
l := Loader{}
data := []byte(`image:
name: registry.docker.io/python:3
username: foo
password: bar
email: email
pipelines:
default:
- step:
script:
- set -ex
- find . -type f -iname "*.pyc" -exec rm -f {} \; || true
- find . -type d -iname __pycache__ -exec rm -rf {} \; || true
- pip install -r dev-requirements.txt
- flake8
- PYTHONPATH=$(pwd) py.test --color=auto --cov=pipelines --cov-report=term-missing tests`)
cfg, err := l.Load("", "", data)
Expect(err).To(BeNil())
expected := &config.Config{
Tasks: map[string]tasks.Task{
"import": &docker.Import{
Files: []string{"."},
},
"login": &docker.Login{
Username: "foo",
Password: "bar",
Server: "registry.docker.io",
},
"default-step-0-0": &docker.Run{
Image: "registry.docker.io/python:3",
WorkDir: "/workspace",
Script: []string{
"set -ex",
"find . -type f -iname \"*.pyc\" -exec rm -f {} \\; || true",
"find . -type d -iname __pycache__ -exec rm -rf {} \\; || true",
"pip install -r dev-requirements.txt",
"flake8",
"PYTHONPATH=$(pwd) py.test --color=auto --cov=pipelines --cov-report=term-missing tests",
},
Shell: "/bin/sh",
},
"logout": &docker.Logout{
Server: "registry.docker.io",
},
},
Plans: map[string]plans.Plan{
"default": {
Stages: []stages.Stage{
stages.Stage{
Name: "stage-0",
Enabled: true,
Run: "on-success",
Concurrent: false,
Environment: nil,
Tasks: []string{"import", "login", "default-step-0-0", "logout"},
},
},
},
},
}
Expect(cfg).To(Equal(expected))
}
func (b *bitbucketSuite) TestLoaderComplexStepImage(t sweet.T) {
l := Loader{}
data := []byte(`pipelines:
default:
- step:
image:
name: python:3
script:
- set -ex
- find . -type f -iname "*.pyc" -exec rm -f {} \; || true
- find . -type d -iname __pycache__ -exec rm -rf {} \; || true
- pip install -r dev-requirements.txt
- flake8
- PYTHONPATH=$(pwd) py.test --color=auto --cov=pipelines --cov-report=term-missing tests`)
cfg, err := l.Load("", "", data)
Expect(err).To(BeNil())
expected := &config.Config{
Tasks: map[string]tasks.Task{
"import": &docker.Import{
Files: []string{"."},
},
"default-step-0-0": &docker.Run{
Image: "python:3",
WorkDir: "/workspace",
Script: []string{
"set -ex",
"find . -type f -iname \"*.pyc\" -exec rm -f {} \\; || true",
"find . -type d -iname __pycache__ -exec rm -rf {} \\; || true",
"pip install -r dev-requirements.txt",
"flake8",
"PYTHONPATH=$(pwd) py.test --color=auto --cov=pipelines --cov-report=term-missing tests",
},
Shell: "/bin/sh",
},
},
Plans: map[string]plans.Plan{
"default": {
Stages: []stages.Stage{
stages.Stage{
Name: "stage-0",
Enabled: true,
Concurrent: false,
Run: "on-success",
Environment: nil,
Tasks: []string{"import", "default-step-0-0"},
},
},
},
},
}
Expect(cfg).To(Equal(expected))
}
func (b *bitbucketSuite) TestLoaderComplexStepImageWithLogin(t sweet.T) {
l := Loader{}
data := []byte(`pipelines:
default:
- step:
image:
name: registry.docker.io/python:3
username: user
password: pass
script:
- set -ex
- find . -type f -iname "*.pyc" -exec rm -f {} \; || true
- find . -type d -iname __pycache__ -exec rm -rf {} \; || true
- pip install -r dev-requirements.txt
- flake8
- PYTHONPATH=$(pwd) py.test --color=auto --cov=pipelines --cov-report=term-missing tests`)
cfg, err := l.Load("", "", data)
Expect(err).To(BeNil())
expected := &config.Config{
Tasks: map[string]tasks.Task{
"import": &docker.Import{
Files: []string{"."},
},
"default-0-login": &docker.Login{
Username: "user",
Password: "pass",
Server: "registry.docker.io",
},
"default-step-0-0": &docker.Run{
Image: "registry.docker.io/python:3",
WorkDir: "/workspace",
Script: []string{
"set -ex",
"find . -type f -iname \"*.pyc\" -exec rm -f {} \\; || true",
"find . -type d -iname __pycache__ -exec rm -rf {} \\; || true",
"pip install -r dev-requirements.txt",
"flake8",
"PYTHONPATH=$(pwd) py.test --color=auto --cov=pipelines --cov-report=term-missing tests",
},
Shell: "/bin/sh",
},
"default-0-logout": &docker.Logout{
Server: "registry.docker.io",
},
},
Plans: map[string]plans.Plan{
"default": {
Stages: []stages.Stage{
stages.Stage{
Name: "stage-0",
Enabled: true,
Concurrent: false,
Run: "on-success",
Environment: nil,
Tasks: []string{"import", "default-0-login", "default-step-0-0", "default-0-logout"},
},
},
},
},
}
Expect(cfg).To(Equal(expected))
}
func (b *bitbucketSuite) TestLoaderDockerMixed(t sweet.T) {
l := Loader{}
data := []byte(`image: gliderlabs/alpine:edge
pipelines:
default:
- step:
script:
- hostname
- docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
- date +%s
- docker build -t atlassian/my-app:$BITBUCKET_COMMIT .
- docker push atlassian/my-app:$BITBUCKET_COMMIT
- date +%s
options:
docker: true
`)
cfg, err := l.Load("", "", data)
Expect(err).To(BeNil())
expected := &config.Config{
Tasks: map[string]tasks.Task{
"import": &docker.Import{
Files: []string{"."},
},
"default-step-0-0": &docker.Run{
Image: "gliderlabs/alpine:edge",
Script: []string{"hostname"},
WorkDir: "/workspace",
Shell: "/bin/sh",
},
"default-step-0-1": &docker.Login{
Username: "$DOCKER_USERNAME",
Password: "$DOCKER_PASSWORD",
},
"default-step-0-2": &docker.Run{
Image: "gliderlabs/alpine:edge",
Script: []string{"date +%s"},
WorkDir: "/workspace",
Shell: "/bin/sh",
},
"default-step-0-3": &docker.Build{
Files: []string{"."},
Tag: "atlassian/my-app:$BITBUCKET_COMMIT",
},
"default-step-0-4": &docker.Push{
Image: "atlassian/my-app:$BITBUCKET_COMMIT",
},
"default-step-0-5": &docker.Run{
Image: "gliderlabs/alpine:edge",
Script: []string{"date +%s"},
WorkDir: "/workspace",
Shell: "/bin/sh",
},
},
Plans: map[string]plans.Plan{
"default": {
Stages: []stages.Stage{
stages.Stage{
Name: "stage-0",
Enabled: true,
Concurrent: false,
Run: "on-success",
Environment: nil,
Tasks: []string{
"import",
"default-step-0-0",
"default-step-0-1",
"default-step-0-2",
"default-step-0-3",
"default-step-0-4",
"default-step-0-5",
},
},
},
},
},
}
Expect(cfg).To(Equal(expected))
}
func (b *bitbucketSuite) TestLoaderDockerSimple(t sweet.T) {
l := Loader{}
data := []byte(`pipelines:
default:
- step:
script:
- docker login -u $DOCKER_USERNAME -p $DOCKER_PASSWORD
- docker build -t atlassian/my-app:$BITBUCKET_COMMIT .
- docker push atlassian/my-app:$BITBUCKET_COMMIT
options:
docker: true
`)
cfg, err := l.Load("", "", data)
Expect(err).To(BeNil())
expected := &config.Config{
Tasks: map[string]tasks.Task{
"import": &docker.Import{
Files: []string{"."},
},
"default-step-0-0": &docker.Login{
Username: "$DOCKER_USERNAME",
Password: "$DOCKER_PASSWORD",
},
"default-step-0-1": &docker.Build{
Files: []string{"."},
Tag: "atlassian/my-app:$BITBUCKET_COMMIT",
},
"default-step-0-2": &docker.Push{
Image: "atlassian/my-app:$BITBUCKET_COMMIT",
},
},
Plans: map[string]plans.Plan{
"default": {
Stages: []stages.Stage{
stages.Stage{
Name: "stage-0",
Enabled: true,
Concurrent: false,
Run: "on-success",
Environment: nil,
Tasks: []string{
"import",
"default-step-0-0",
"default-step-0-1",
"default-step-0-2",
},
},
},
},
},
}
Expect(cfg).To(Equal(expected))
}