Skip to content

Test framework #11

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 23 commits into from
Feb 26, 2018
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM scratch

ADD bin/arangodb_operator_test /usr/bin/

ENTRYPOINT [ "/usr/bin/arangodb_operator_test" ]
68 changes: 68 additions & 0 deletions Jenkinsfile.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
def notifySlack(String buildStatus = 'STARTED') {
// Build status of null means success.
buildStatus = buildStatus ?: 'SUCCESS'

def color

if (buildStatus == 'STARTED') {
color = '#D4DADF'
} else if (buildStatus == 'SUCCESS') {
color = '#BDFFC3'
} else if (buildStatus == 'UNSTABLE') {
color = '#FFFE89'
} else {
color = '#FF9FA1'
}

def msg = "${buildStatus}: `${env.JOB_NAME}` #${env.BUILD_NUMBER}: ${env.GIT_COMMIT}\n${env.BUILD_URL}"

slackSend(color: color, channel: '#status-k8s', message: msg)
}

pipeline {
options {
buildDiscarder(logRotator(daysToKeepStr: '7', numToKeepStr: '10'))
}
agent any
parameters {
string(name: 'TESTNAMESPACE', defaultValue: 'jenkins', description: 'TESTNAMESPACE sets the kubernetes namespace to ru tests in (this must be short!!)', )
}
stages {
stage('Build') {
steps {
timestamps {
withEnv([
"IMAGETAG=${env.GIT_COMMIT}",
]) {
sh "make"
}
}
}
}
stage('Test') {
steps {
timestamps {
lock("${params.TESTNAMESPACE}-${env.GIT_COMMIT}") {
withEnv([
"TESTNAMESPACE=${params.TESTNAMESPACE}-${env.GIT_COMMIT}",
"IMAGETAG=${env.GIT_COMMIT}",
"PUSHIMAGES=1",
]) {
sh "make run-tests"
}
}
}
}
}
}

post {
failure {
notifySlack('FAILURE')
}

success {
notifySlack('SUCCESS')
}
}
}
60 changes: 54 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,31 @@ PULSAR := $(GOBUILDDIR)/bin/pulsar$(shell go env GOEXE)
ifndef DOCKERNAMESPACE
DOCKERNAMESPACE := arangodb
endif
ifndef DOCKERFILE
DOCKERFILE := Dockerfile
#DOCKERFILE := Dockerfile.debug
DOCKERFILE := Dockerfile
DOCKERTESTFILE := Dockerfile.test

ifdef IMAGETAG
IMAGESUFFIX := ":$(IMAGETAG)"
endif

ifndef OPERATORIMAGE
OPERATORIMAGE := $(DOCKERNAMESPACE)/arangodb-operator$(IMAGESUFFIX)
endif
ifndef TESTIMAGE
TESTIMAGE := $(DOCKERNAMESPACE)/arangodb-operator-test$(IMAGESUFFIX)
endif

BINNAME := $(PROJECT)
BIN := $(BINDIR)/$(BINNAME)
TESTBINNAME := $(PROJECT)_test
TESTBIN := $(BINDIR)/$(TESTBINNAME)
RELEASE := $(GOBUILDDIR)/bin/release
GHRELEASE := $(GOBUILDDIR)/bin/github-release

ifndef TESTNAMESPACE
TESTNAMESPACE := arangodb-operator-tests
endif

SOURCES := $(shell find $(SRCDIR) -name '*.go' -not -path './test/*')

.PHONY: all clean deps docker update-vendor update-generated verify-generated
Expand Down Expand Up @@ -77,6 +92,7 @@ update-vendor:
k8s.io/client-go/... \
k8s.io/gengo/args \
k8s.io/apiextensions-apiserver \
github.com/arangodb/go-driver \
github.com/cenkalti/backoff \
github.com/dchest/uniuri \
github.com/dgrijalva/jwt-go \
Expand Down Expand Up @@ -122,11 +138,43 @@ $(BIN): $(GOBUILDDIR) $(SOURCES)
go build -installsuffix cgo -ldflags "-X main.projectVersion=$(VERSION) -X main.projectBuild=$(COMMIT)" -o /usr/code/bin/$(BINNAME) $(REPOPATH)

docker: $(BIN)
docker build -f $(DOCKERFILE) -t arangodb/arangodb-operator .
docker build -f $(DOCKERFILE) -t $(OPERATORIMAGE) .

# Testing

$(TESTBIN): $(GOBUILDDIR) $(SOURCES)
@mkdir -p $(BINDIR)
docker run \
--rm \
-v $(SRCDIR):/usr/code \
-e GOPATH=/usr/code/.gobuild \
-e GOOS=linux \
-e GOARCH=amd64 \
-e CGO_ENABLED=0 \
-w /usr/code/ \
golang:$(GOVERSION) \
go test -c -installsuffix cgo -ldflags "-X main.projectVersion=$(VERSION) -X main.projectBuild=$(COMMIT)" -o /usr/code/bin/$(TESTBINNAME) $(REPOPATH)/tests

docker-test: $(TESTBIN)
docker build --quiet -f $(DOCKERTESTFILE) -t $(TESTIMAGE) .

run-tests: docker-test
ifdef PUSHIMAGES
docker push $(OPERATORIMAGE)
docker push $(TESTIMAGE)
endif
$(ROOTDIR)/scripts/kube_delete_namespace.sh $(TESTNAMESPACE)
kubectl create namespace $(TESTNAMESPACE)
$(ROOTDIR)/examples/setup-rbac.sh --namespace=$(TESTNAMESPACE)
$(ROOTDIR)/scripts/kube_create_operator.sh $(TESTNAMESPACE) $(OPERATORIMAGE)
kubectl --namespace $(TESTNAMESPACE) run arangodb-operator-test -i --rm --quiet --restart=Never --image=$(TESTIMAGE) --env="TEST_NAMESPACE=$(TESTNAMESPACE)" -- -test.v
kubectl delete namespace $(TESTNAMESPACE) --ignore-not-found --now

# Release building

docker-push: docker
ifneq ($(DOCKERNAMESPACE), arangodb)
docker tag arangodb/arangodb-operator $(DOCKERNAMESPACE)/arangodb-operator
docker tag $(OPERATORIMAGE) $(DOCKERNAMESPACE)/arangodb-operator
endif
docker push $(DOCKERNAMESPACE)/arangodb-operator

Expand Down Expand Up @@ -161,7 +209,7 @@ minikube-start:
minikube start --cpus=4 --memory=6144

delete-operator:
kubectl delete -f examples/deployment.yaml || true
kubectl delete -f examples/deployment.yaml --ignore-not-found

redeploy-operator: delete-operator
kubectl create -f examples/deployment.yaml
Expand Down
8 changes: 8 additions & 0 deletions deps/github.com/arangodb/go-driver/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export GOBUILDDIR=$(pwd)/.gobuild
export GOPATH=$GOBUILDDIR:$GOPATH
PATH_add $GOBUILDDIR/bin

if [ ! -e ${GOBUILDDIR} ]; then
mkdir -p ${GOBUILDDIR}/src/github.com/arangodb/
ln -s ../../../.. ${GOBUILDDIR}/src/github.com/arangodb/go-driver
fi
1 change: 1 addition & 0 deletions deps/github.com/arangodb/go-driver/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.gobuild
14 changes: 14 additions & 0 deletions deps/github.com/arangodb/go-driver/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
sudo: required

services:
- docker

language: go

env:
- TEST_SUITE=run-tests-http
- TEST_SUITE=run-tests-single ARANGODB=arangodb:3.1
- TEST_SUITE=run-tests-single ARANGODB=arangodb/arangodb:latest
- TEST_SUITE=run-tests-single ARANGODB=arangodb/arangodb-preview:latest

script: make $TEST_SUITE
37 changes: 37 additions & 0 deletions deps/github.com/arangodb/go-driver/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Place your settings in this file to overwrite default and user settings.
{
"fileHeaderComment.parameter":{
"*":{
"commentprefix": "//",
"company": "ArangoDB GmbH, Cologne, Germany",
"author": "Ewout Prangsma"
}
},
"fileHeaderComment.template":{
"*":[
"${commentprefix} ",
"${commentprefix} DISCLAIMER",
"${commentprefix} ",
"${commentprefix} Copyright ${year} ArangoDB GmbH, Cologne, Germany",
"${commentprefix} ",
"${commentprefix} Licensed under the Apache License, Version 2.0 (the \"License\");",
"${commentprefix} you may not use this file except in compliance with the License.",
"${commentprefix} You may obtain a copy of the License at",
"${commentprefix} ",
"${commentprefix} http://www.apache.org/licenses/LICENSE-2.0",
"${commentprefix} ",
"${commentprefix} Unless required by applicable law or agreed to in writing, software",
"${commentprefix} distributed under the License is distributed on an \"AS IS\" BASIS,",
"${commentprefix} WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.",
"${commentprefix} See the License for the specific language governing permissions and",
"${commentprefix} limitations under the License.",
"${commentprefix} ",
"${commentprefix} Copyright holder is ArangoDB GmbH, Cologne, Germany",
"${commentprefix} ",
"${commentprefix} Author ${author}",
"${commentprefix} ",
""
]
},
"go.gopath": "${workspaceRoot}/.gobuild"
}
63 changes: 63 additions & 0 deletions deps/github.com/arangodb/go-driver/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
Contributing
============

We welcome bug fixes and patches from 3rd party contributors. Please
see the [Contributor Agreement](https://www.arangodb.com/community#contribute)
for details.

Please follow these guidelines if you want to contribute to ArangoDB:

Reporting Bugs
--------------

When reporting bugs, please use our issue tracker on GitHub. Please make sure
to include the version number of ArangoDB and the commit hash of the go-driver in your bug report, along with the
platform you are using (e.g. `Linux OpenSuSE x86_64`). Please also include the
ArangoDB startup mode (daemon, console, supervisor mode), type of connection used
towards ArangoDB plus any special configuration.
This will help us reproducing and finding bugs.

Please also take the time to check there are no similar/identical issues open
yet.

Contributing features, documentation, tests
-------------------------------------------

* Create a new branch in your fork, based on the **master** branch

* Develop and test your modifications there

* Commit as you like, but preferably in logical chunks. Use meaningful commit
messages and make sure you do not commit unnecessary files (e.g. object
files). It is normally a good idea to reference the issue number from the
commit message so the issues will get updated automatically with comments.

* If the modifications change any documented behavior or add new features,
document the changes and provide application tests in the `test` folder.
All documentation should be written in American English (AE).

* When done, run the complete test suite (`make run-tests`) and make sure all tests pass.

* When finished, push the changes to your GitHub repository and send a pull
request from your fork to the ArangoDB repository. Please make sure to select
the appropriate branches there. This will most likely be **master**.

* You must use the Apache License for your changes and have signed our
[CLA](https://www.arangodb.com/documents/cla.pdf). We cannot accept pull requests
from contributors that didn't sign the CLA.

* Please let us know if you plan to work on a ticket. This way we can make sure
redundant work is avoided.


Additional Resources
--------------------

* [ArangoDB website](https://www.arangodb.com/)

* [ArangoDB on Twitter](https://twitter.com/arangodb)

* [General GitHub documentation](https://help.github.com/)

* [GitHub pull request documentation](https://help.github.com/send-pull-requests/)

Loading