grim/convey

5abe317f3969
Parents aefbec4df2b5
Children 096a15e82c7a
The start of loader tests for bitbucket-pipelines. refs #92
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/bitbucket/loader_test.go Tue May 02 22:50:49 2017 -0500
@@ -0,0 +1,146 @@
+/*
+ * 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 (
+ "testing"
+
+ . "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 *testing.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": &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,
+ Always: false,
+ Concurrent: false,
+ Environment: nil,
+ Tasks: []string{"import", "default-step-0"},
+ },
+ },
+ },
+ },
+ }
+
+ Expect(cfg).To(Equal(expected))
+}
+
+func (b *bitbucketSuite) TestLoaderDocker(t *testing.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,
+ Always: false,
+ Concurrent: false,
+ Environment: nil,
+ Tasks: []string{
+ "import",
+ "default-step-0-0",
+ "default-step-0-1",
+ "default-step-0-2",
+ },
+ },
+ },
+ },
+ },
+ }
+
+ Expect(cfg).To(Equal(expected))
+}