Skip to content

Commit

Permalink
Continuous Integration Workflow for docker-plain quickstarter
Browse files Browse the repository at this point in the history
Adding 'tests' folder with:
	utils: go code with utilities to help writing tests
	scripts: some utility scripts
	docker-plain: docker-plain tests
	setup-tests: go code for setting up missing infrastructure for QS tests

Docker plain tests works as follows:
	First deploy the QS using the webhook-proxy
	Trigger build by calling webhook-proxy
	Test existence of resources
	Test if commit status is flagged as successful
  • Loading branch information
hugowschneider authored and Wruck_Schneider,Dr.,Hugo (BI X) BIX-DE-I committed Jan 15, 2020
1 parent 7f8c371 commit 843534f
Show file tree
Hide file tree
Showing 16 changed files with 1,027 additions and 0 deletions.
96 changes: 96 additions & 0 deletions .github/workflows/continuous-integration-workflow.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
name: Continous Integration Tests
on:
pull_request:
branches:
- master
jobs:
test:
name: Docker plain provisioning
runs-on: ubuntu-16.04
steps:
-
name: GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: jq . <<< "${GITHUB_CONTEXT}"
-
name: Checkout QuickStarters repository
uses: actions/[email protected]
with:
fetch-depth: 0
path: ods-quickstarters
-
name: Checkout ODS Core
uses: actions/[email protected]
with:
fetch-depth: 0
repository: opendevstack/ods-core
ref: master
path: ods-core
-
name: Checkout ODS Jenkins Shared Library
uses: actions/[email protected]
with:
fetch-depth: 0
repository: BIX-Digital/ods-jenkins-shared-library
ref: invalid/curl-http-only
path: ods-jenkins-shared-library
-
name: Setup Go 1.13
uses: actions/[email protected]
with:
version: 1.13
-
name: Download OpenShift Client
run: |
wget https://github.com/openshift/origin/releases/download/v3.11.0/openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz
tar -xzvf openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit.tar.gz
sudo mv openshift-origin-client-tools-v3.11.0-0cbc58b-linux-64bit/oc /usr/local/bin/oc
-
name: Download Tailor
run: |
curl -LO "https://github.com/opendevstack/tailor/releases/download/v0.11.0/tailor-linux-amd64"
chmod +x tailor-linux-amd64
sudo mv tailor-linux-amd64 /usr/local/bin/tailor
-
name: Tailor version
run: tailor version
-
name: OpenShift client version
run: oc version
-
name: jq version
run: jq --version
-
name: golang version
run: go version
-
name: Docker version
run: docker --version
-
name: Network before changes
run: ifconfig
-
name: Configure docker network and insecure registries
run: ls -la && ls -la ./tests && ./tests/scripts/apply-docker-settings.sh
working-directory: ${{ format('{0}/ods-core', github.workspace) }}
-
name: Start OC cluster
run: oc cluster up --base-dir=${HOME}/openshift.local.clusterup --routing-suffix 172.17.0.1.nip.io --public-hostname 172.17.0.1 --enable=centos-imagestreams --enable=persistent-volumes --enable=registry --enable=router
-
name: Login into the cluster
run: oc login -u system:admin
-
name: Create test infrastructure
run: |
mkdir -p ods-config
./tests/scripts/recreate-test-infrastructure.sh
working-directory: ${{ format('{0}/ods-core', github.workspace) }}
-
name: Test setup
run: make setup-tests
working-directory: ${{ format('{0}/ods-quickstarters/tests', github.workspace) }}
-
name: Run tests
run: make test
working-directory: ${{ format('{0}/ods-quickstarters/tests', github.workspace) }}
1 change: 1 addition & 0 deletions tests/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test-setup.bin
12 changes: 12 additions & 0 deletions tests/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.PHONY: test lint

test: docker-plain/jenkinsfile_test.go go.mod go.sum
go test -v github.com/opendevstack/ods-quickstarters/tests/docker-plain

setup-tests: test-setup/main.go
go build -o test-setup.bin test-setup/main.go
./test-setup.bin
./scripts/setup-mocked-ods-repo.sh --ods-ref cicdtests
lint:
echo "Checking code ..."
golangci-lint run
96 changes: 96 additions & 0 deletions tests/docker-plain/jenkinsfile_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package docker_plain

import (
"encoding/json"
"fmt"
coreUtils "github.com/opendevstack/ods-core/tests/utils"
"github.com/opendevstack/ods-quickstarters/tests/utils"
"log"
"net/http"
"strings"
"testing"
)

func TestJenkinsFile(t *testing.T) {

values, err := utils.ReadConfiguration()
if err != nil {
t.Fatal(err)
}

const component_id = "docker-plain-test"
err = utils.RunJenkinsFile(
"ods-quickstarters",
"opendevstack",
"cicdtests",
coreUtils.PROJECT_NAME,
"docker-plain/Jenkinsfile",
"unitt-cd",
coreUtils.EnvPair{
Name: "COMPONENT_ID",
Value: component_id,
},
coreUtils.EnvPair{
Name: "GIT_URL_HTTP",
Value: fmt.Sprintf("%s/unitt/docker-plain-test.git", values["REPO_BASE"]),
},
)
if err != nil {
t.Fatal(err)
}

err = utils.RunJenkinsFile(
component_id,
"unitt",
"master",
coreUtils.PROJECT_NAME,
"Jenkinsfile",
"unitt-cd",
coreUtils.EnvPair{
Name: "COMPONENT_ID",
Value: component_id,
},
)
if err != nil {
t.Fatal(err)
}

resourcesInTest := utils.Resources{
Namespace: coreUtils.PROJECT_NAME_TEST,
ImageTags: []utils.ImageTag{{Name: component_id, Tag: "latest"}},
BuildConfigs: []string{component_id},
DeploymentConfigs: []string{component_id},
Services: []string{component_id},
ImageStreams: []string{component_id},
}

utils.CheckResources(resourcesInTest, t)

stdout, stderr, err := coreUtils.RunCommand("docker", []string{"exec", "mockbucket", "sh", "-c", "cd /scm/unitt/docker-plain-test.git && git rev-parse HEAD"}, []string{})
if err != nil {
t.Fatalf("Docker exec failed:%s\nStdOut: %s\nStdErr: %s", err, stdout, stderr)
}

client := &http.Client{}
url := fmt.Sprintf("http://%s/rest/build-status/1.0/commits/%s", values["BITBUCKET_HOST"], strings.TrimSuffix(stdout, "\n"))
request, err := http.NewRequest("GET", url, nil)
if err != nil {
log.Fatal(err)
}
request.SetBasicAuth(values["CD_USER_ID"], values["CD_USER_PWD"])
response, err := client.Do(request)
if err != nil {
log.Fatal(err)
}

commitStatus := utils.CommitStatus{}
err = json.NewDecoder(response.Body).Decode(&commitStatus)
if err != nil {
t.Fatal(err)
}

if commitStatus.State != "SUCCESSFUL" {
t.Error("The commit status should have been SUCCESSFUL")
}

}
17 changes: 17 additions & 0 deletions tests/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module github.com/opendevstack/ods-quickstarters/tests

go 1.13

require (
github.com/google/btree v1.0.0 // indirect
github.com/googleapis/gnostic v0.3.1 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/opendevstack/mockbucket v0.0.0-20191220083823-53b37b3fa3fd // indirect
github.com/opendevstack/ods-core/tests v0.0.0-20200110113746-2e6aa267ea88
github.com/openshift/api v3.9.0+incompatible
github.com/openshift/client-go v3.9.0+incompatible
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
k8s.io/api v0.0.0-20190222213804-5cb15d344471
k8s.io/apimachinery v0.0.0-20190221213512-86fb29eff628
k8s.io/client-go v0.0.0-20190228174230-b40b2a5939e4
)
Loading

0 comments on commit 843534f

Please sign in to comment.