Skip to content

Commit b96da3b

Browse files
authored
Merge pull request #11 from arangodb/test-framework
Test framework
2 parents 174b449 + 8bbebc8 commit b96da3b

File tree

261 files changed

+44688
-19
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

261 files changed

+44688
-19
lines changed

Dockerfile.test

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
FROM scratch
2+
3+
ADD bin/arangodb_operator_test /usr/bin/
4+
5+
ENTRYPOINT [ "/usr/bin/arangodb_operator_test" ]

Jenkinsfile.groovy

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
def notifySlack(String buildStatus = 'STARTED') {
2+
// Build status of null means success.
3+
buildStatus = buildStatus ?: 'SUCCESS'
4+
5+
def color
6+
7+
if (buildStatus == 'STARTED') {
8+
color = '#D4DADF'
9+
} else if (buildStatus == 'SUCCESS') {
10+
color = '#BDFFC3'
11+
} else if (buildStatus == 'UNSTABLE') {
12+
color = '#FFFE89'
13+
} else {
14+
color = '#FF9FA1'
15+
}
16+
17+
def msg = "${buildStatus}: `${env.JOB_NAME}` #${env.BUILD_NUMBER}: ${env.GIT_COMMIT}\n${env.BUILD_URL}"
18+
19+
slackSend(color: color, channel: '#status-k8s', message: msg)
20+
}
21+
22+
pipeline {
23+
options {
24+
buildDiscarder(logRotator(daysToKeepStr: '7', numToKeepStr: '10'))
25+
}
26+
agent any
27+
parameters {
28+
string(name: 'KUBECONFIG', defaultValue: '/home/jenkins/.kube/scw-183a3b', description: 'KUBECONFIG controls which k8s cluster is used', )
29+
string(name: 'TESTNAMESPACE', defaultValue: 'jenkins', description: 'TESTNAMESPACE sets the kubernetes namespace to ru tests in (this must be short!!)', )
30+
}
31+
stages {
32+
stage('Build') {
33+
steps {
34+
timestamps {
35+
withEnv([
36+
"IMAGETAG=${env.GIT_COMMIT}",
37+
]) {
38+
sh "make"
39+
}
40+
}
41+
}
42+
}
43+
stage('Test') {
44+
steps {
45+
timestamps {
46+
lock("${params.TESTNAMESPACE}-${env.GIT_COMMIT}") {
47+
withEnv([
48+
"KUBECONFIG=${params.KUBECONFIG}",
49+
"TESTNAMESPACE=${params.TESTNAMESPACE}-${env.GIT_COMMIT}",
50+
"IMAGETAG=${env.GIT_COMMIT}",
51+
"PUSHIMAGES=1",
52+
]) {
53+
sh "make run-tests"
54+
}
55+
}
56+
}
57+
}
58+
}
59+
}
60+
61+
post {
62+
failure {
63+
notifySlack('FAILURE')
64+
}
65+
66+
success {
67+
notifySlack('SUCCESS')
68+
}
69+
}
70+
}

Makefile

+54-6
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,31 @@ PULSAR := $(GOBUILDDIR)/bin/pulsar$(shell go env GOEXE)
2727
ifndef DOCKERNAMESPACE
2828
DOCKERNAMESPACE := arangodb
2929
endif
30-
ifndef DOCKERFILE
31-
DOCKERFILE := Dockerfile
32-
#DOCKERFILE := Dockerfile.debug
30+
DOCKERFILE := Dockerfile
31+
DOCKERTESTFILE := Dockerfile.test
32+
33+
ifdef IMAGETAG
34+
IMAGESUFFIX := ":$(IMAGETAG)"
35+
endif
36+
37+
ifndef OPERATORIMAGE
38+
OPERATORIMAGE := $(DOCKERNAMESPACE)/arangodb-operator$(IMAGESUFFIX)
39+
endif
40+
ifndef TESTIMAGE
41+
TESTIMAGE := $(DOCKERNAMESPACE)/arangodb-operator-test$(IMAGESUFFIX)
3342
endif
3443

3544
BINNAME := $(PROJECT)
3645
BIN := $(BINDIR)/$(BINNAME)
46+
TESTBINNAME := $(PROJECT)_test
47+
TESTBIN := $(BINDIR)/$(TESTBINNAME)
3748
RELEASE := $(GOBUILDDIR)/bin/release
3849
GHRELEASE := $(GOBUILDDIR)/bin/github-release
3950

51+
ifndef TESTNAMESPACE
52+
TESTNAMESPACE := arangodb-operator-tests
53+
endif
54+
4055
SOURCES := $(shell find $(SRCDIR) -name '*.go' -not -path './test/*')
4156

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

124140
docker: $(BIN)
125-
docker build -f $(DOCKERFILE) -t arangodb/arangodb-operator .
141+
docker build -f $(DOCKERFILE) -t $(OPERATORIMAGE) .
142+
143+
# Testing
144+
145+
$(TESTBIN): $(GOBUILDDIR) $(SOURCES)
146+
@mkdir -p $(BINDIR)
147+
docker run \
148+
--rm \
149+
-v $(SRCDIR):/usr/code \
150+
-e GOPATH=/usr/code/.gobuild \
151+
-e GOOS=linux \
152+
-e GOARCH=amd64 \
153+
-e CGO_ENABLED=0 \
154+
-w /usr/code/ \
155+
golang:$(GOVERSION) \
156+
go test -c -installsuffix cgo -ldflags "-X main.projectVersion=$(VERSION) -X main.projectBuild=$(COMMIT)" -o /usr/code/bin/$(TESTBINNAME) $(REPOPATH)/tests
157+
158+
docker-test: $(TESTBIN)
159+
docker build --quiet -f $(DOCKERTESTFILE) -t $(TESTIMAGE) .
160+
161+
run-tests: docker-test
162+
ifdef PUSHIMAGES
163+
docker push $(OPERATORIMAGE)
164+
docker push $(TESTIMAGE)
165+
endif
166+
$(ROOTDIR)/scripts/kube_delete_namespace.sh $(TESTNAMESPACE)
167+
kubectl create namespace $(TESTNAMESPACE)
168+
$(ROOTDIR)/examples/setup-rbac.sh --namespace=$(TESTNAMESPACE)
169+
$(ROOTDIR)/scripts/kube_create_operator.sh $(TESTNAMESPACE) $(OPERATORIMAGE)
170+
kubectl --namespace $(TESTNAMESPACE) run arangodb-operator-test -i --rm --quiet --restart=Never --image=$(TESTIMAGE) --env="TEST_NAMESPACE=$(TESTNAMESPACE)" -- -test.v
171+
kubectl delete namespace $(TESTNAMESPACE) --ignore-not-found --now
172+
173+
# Release building
126174

127175
docker-push: docker
128176
ifneq ($(DOCKERNAMESPACE), arangodb)
129-
docker tag arangodb/arangodb-operator $(DOCKERNAMESPACE)/arangodb-operator
177+
docker tag $(OPERATORIMAGE) $(DOCKERNAMESPACE)/arangodb-operator
130178
endif
131179
docker push $(DOCKERNAMESPACE)/arangodb-operator
132180

@@ -161,7 +209,7 @@ minikube-start:
161209
minikube start --cpus=4 --memory=6144
162210

163211
delete-operator:
164-
kubectl delete -f examples/deployment.yaml || true
212+
kubectl delete -f examples/deployment.yaml --ignore-not-found
165213

166214
redeploy-operator: delete-operator
167215
kubectl create -f examples/deployment.yaml
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
export GOBUILDDIR=$(pwd)/.gobuild
2+
export GOPATH=$GOBUILDDIR:$GOPATH
3+
PATH_add $GOBUILDDIR/bin
4+
5+
if [ ! -e ${GOBUILDDIR} ]; then
6+
mkdir -p ${GOBUILDDIR}/src/github.com/arangodb/
7+
ln -s ../../../.. ${GOBUILDDIR}/src/github.com/arangodb/go-driver
8+
fi
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.gobuild
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
sudo: required
2+
3+
services:
4+
- docker
5+
6+
language: go
7+
8+
env:
9+
- TEST_SUITE=run-tests-http
10+
- TEST_SUITE=run-tests-single ARANGODB=arangodb:3.1
11+
- TEST_SUITE=run-tests-single ARANGODB=arangodb/arangodb:latest
12+
- TEST_SUITE=run-tests-single ARANGODB=arangodb/arangodb-preview:latest
13+
14+
script: make $TEST_SUITE
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
// Place your settings in this file to overwrite default and user settings.
2+
{
3+
"fileHeaderComment.parameter":{
4+
"*":{
5+
"commentprefix": "//",
6+
"company": "ArangoDB GmbH, Cologne, Germany",
7+
"author": "Ewout Prangsma"
8+
}
9+
},
10+
"fileHeaderComment.template":{
11+
"*":[
12+
"${commentprefix} ",
13+
"${commentprefix} DISCLAIMER",
14+
"${commentprefix} ",
15+
"${commentprefix} Copyright ${year} ArangoDB GmbH, Cologne, Germany",
16+
"${commentprefix} ",
17+
"${commentprefix} Licensed under the Apache License, Version 2.0 (the \"License\");",
18+
"${commentprefix} you may not use this file except in compliance with the License.",
19+
"${commentprefix} You may obtain a copy of the License at",
20+
"${commentprefix} ",
21+
"${commentprefix} http://www.apache.org/licenses/LICENSE-2.0",
22+
"${commentprefix} ",
23+
"${commentprefix} Unless required by applicable law or agreed to in writing, software",
24+
"${commentprefix} distributed under the License is distributed on an \"AS IS\" BASIS,",
25+
"${commentprefix} WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.",
26+
"${commentprefix} See the License for the specific language governing permissions and",
27+
"${commentprefix} limitations under the License.",
28+
"${commentprefix} ",
29+
"${commentprefix} Copyright holder is ArangoDB GmbH, Cologne, Germany",
30+
"${commentprefix} ",
31+
"${commentprefix} Author ${author}",
32+
"${commentprefix} ",
33+
""
34+
]
35+
},
36+
"go.gopath": "${workspaceRoot}/.gobuild"
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
Contributing
2+
============
3+
4+
We welcome bug fixes and patches from 3rd party contributors. Please
5+
see the [Contributor Agreement](https://www.arangodb.com/community#contribute)
6+
for details.
7+
8+
Please follow these guidelines if you want to contribute to ArangoDB:
9+
10+
Reporting Bugs
11+
--------------
12+
13+
When reporting bugs, please use our issue tracker on GitHub. Please make sure
14+
to include the version number of ArangoDB and the commit hash of the go-driver in your bug report, along with the
15+
platform you are using (e.g. `Linux OpenSuSE x86_64`). Please also include the
16+
ArangoDB startup mode (daemon, console, supervisor mode), type of connection used
17+
towards ArangoDB plus any special configuration.
18+
This will help us reproducing and finding bugs.
19+
20+
Please also take the time to check there are no similar/identical issues open
21+
yet.
22+
23+
Contributing features, documentation, tests
24+
-------------------------------------------
25+
26+
* Create a new branch in your fork, based on the **master** branch
27+
28+
* Develop and test your modifications there
29+
30+
* Commit as you like, but preferably in logical chunks. Use meaningful commit
31+
messages and make sure you do not commit unnecessary files (e.g. object
32+
files). It is normally a good idea to reference the issue number from the
33+
commit message so the issues will get updated automatically with comments.
34+
35+
* If the modifications change any documented behavior or add new features,
36+
document the changes and provide application tests in the `test` folder.
37+
All documentation should be written in American English (AE).
38+
39+
* When done, run the complete test suite (`make run-tests`) and make sure all tests pass.
40+
41+
* When finished, push the changes to your GitHub repository and send a pull
42+
request from your fork to the ArangoDB repository. Please make sure to select
43+
the appropriate branches there. This will most likely be **master**.
44+
45+
* You must use the Apache License for your changes and have signed our
46+
[CLA](https://www.arangodb.com/documents/cla.pdf). We cannot accept pull requests
47+
from contributors that didn't sign the CLA.
48+
49+
* Please let us know if you plan to work on a ticket. This way we can make sure
50+
redundant work is avoided.
51+
52+
53+
Additional Resources
54+
--------------------
55+
56+
* [ArangoDB website](https://www.arangodb.com/)
57+
58+
* [ArangoDB on Twitter](https://twitter.com/arangodb)
59+
60+
* [General GitHub documentation](https://help.github.com/)
61+
62+
* [GitHub pull request documentation](https://help.github.com/send-pull-requests/)
63+

0 commit comments

Comments
 (0)