Skip to content
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

[Task] Use the travisCI job to testing the unit-test and integration-test in the same time. #215

Merged
merged 7 commits into from
Aug 2, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
73 changes: 30 additions & 43 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,61 +23,48 @@ notifications:
secure: k4ElQjxzBFlHcSHny92pauJNsb6HDvK4BVnmc0wwm9SViQLHj/8yoRlfkUahQ6oAvnl2FaT5DN7gpWDxg5JDsEwvvtJfcqWzv0WIG911fCUlWEZ358DVcs59MOml2A13P6k7fbIxLSQD7yD4LJbnHg61ZFcj2yxy3H3KI3KUOvOrQCNk/ptIKAPahLLmlX4x6nO3bKT9zXOWZKzqSoERMBNuhdEU6BDggaQTxryz8uPoNJe1cb6WYcqqV7CXX/UTB1m0sVoJceAre5ukehp0uv+b0wjYSKm8bviZcFyy2W9eafnYeqyJht7U4Tqlw/l6xDbS3jPmFE7rMyGUDxkz92ZOr72xca7dRBSo6TXpJ4yHl4J/fHeHfMS1Di3OHHp/T4FgPykpbm+2lCCCR79bZ5XjnhDOimO35fzn+c8lHHqEgsdYK0cgmhbRs51A0lPjiWseosQ0tNQ/STd5FL+KDidJ+qHcahVSO0Afwwl7s573GuXDegAKCMJ09TMKSEVvXa8yZFqoo9UG+g+L6a0Mm71pymn+eEhAPXpl8ZzM2qjmTYdaIA/XLHHet49AkNdY7/27o+itXgA/Vh0DAcOHeTO1fJ17sVCP2R72KGRahWLRV5PpeiNnK7Xg2ZXuYaqA//gyjyzz3fVoImGHgjA80gS/xqPy79LxR3K5LR2TJjw=

before_install:
- go get -u github.com/kardianos/govendor
- sudo apt-get install -y git build-essential openvswitch-switch socat jq httpie
- sudo add-apt-repository ppa:duggan/bats --yes
- sudo apt-get update -qq
- sudo apt-get install -qq bats

install:
- make pre-build
- go get -u github.com/kardianos/govendor
- sudo apt-get install -y socat openvswitch-switch
- curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.9.0/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
- curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
- curl -L https://storage.googleapis.com/kubernetes-helm/helm-v2.9.1-linux-amd64.tar.gz > helm-v2.9.1-linux-amd64.tar.gz && tar -zxvf helm-v2.9.1-linux-amd64.tar.gz && chmod +x linux-amd64/helm && sudo mv linux-amd64/helm /usr/local/bin/helm

before_script:
# Make root mounted as rshared to fix kube-dns issues.
- sudo mount --make-rshared /
# Make /sys mounted as rshared to support cadvisor
- sudo mount --make-rshared /sys
- sudo mount --make-rshared /var/run
# # Download kubectl, which is a requirement for using minikube.
- curl -Lo kubectl https://storage.googleapis.com/kubernetes-release/release/v1.9.0/bin/linux/amd64/kubectl && chmod +x kubectl && sudo mv kubectl /usr/local/bin/
# # Download minikube.
- curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 && chmod +x minikube && sudo mv minikube /usr/local/bin/
# Download kubectl, which is a requirement for using minikube.
- sudo minikube start --vm-driver=none --bootstrapper=localkube --kubernetes-version=v1.9.0 --extra-config=apiserver.Authorization.Mode=RBAC
# # Fix the kubectl context, as it's often stale.
# Fix the kubectl context, as it's often stale.
- minikube update-context
# # Wait for Kubernetes to be up and ready.
- JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'; until kubectl get nodes -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do sleep 1; done
# # Enable rbac.
- kubectl create clusterrolebinding add-on-cluster-admin --clusterrole=cluster-admin --serviceaccount=kube-system:default
# # Download Helm.
- curl -L https://storage.googleapis.com/kubernetes-helm/helm-v2.9.1-linux-amd64.tar.gz > helm-v2.9.1-linux-amd64.tar.gz && tar -zxvf helm-v2.9.1-linux-amd64.tar.gz && chmod +x linux-amd64/helm && sudo mv linux-amd64/helm /usr/local/bin/helm
# # Install nsenter
# Install nsenter
- docker run -v /usr/local/bin:/hostbin hwchiu/ubuntu-nsenter cp /nsenter /hostbin/nsenter

script:
- kubectl cluster-info
# Verify kube-addon-manager.
# # kube-addon-manager is responsible for managing other kubernetes components, such as kube-dns, dashboard, storage-provisioner..
- JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'; until kubectl -n kube-system get pods -lcomponent=kube-addon-manager -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do sleep 1;echo "waiting for kube-addon-manager to be available"; kubectl get pods --all-namespaces; done
# # Wait for kube-dns to be ready.
- JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'; until kubectl -n kube-system get pods -lk8s-app=kube-dns -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do sleep 1;echo "waiting for kube-dns to be available"; kubectl get pods --all-namespaces; done
- make build
# # Initial helm
# Initial helm
- make apps.init-helm
# # Check if tiller is ready
# Check if tiller is ready
- JSONPATH='{range .items[*]}{@.metadata.name}:{range @.status.conditions[*]}{@.type}={@.status};{end}{end}'; until kubectl -n kube-system get pods -lname=tiller -o jsonpath="$JSONPATH" 2>&1 | grep -q "Ready=True"; do sleep 1; echo "wait the tiller to be available"; done
- helm version
# # Launch apps (mongodb, prometheus)
# # Enable rbac.
- kubectl create clusterrolebinding add-on-cluster-admin --clusterrole=cluster-admin --serviceaccount=kube-system:default
# Launch apps (mongodb, prometheus)
- make apps.launch
# # Check if prometheus is ready
# Check if prometheus is ready
- until curl --connect-timeout 1 -sL -w "%{http_code}\\n" http://`kubectl get service -n vortex prometheus -o jsonpath="{.spec.clusterIP}"`:9090/api/v1/query?query=prometheus_build_info -o /dev/null | grep 200; do sleep 1; echo "wait the prometheus to be available"; kubectl get pods --all-namespaces; done
- until [ `kubectl -n vortex get --no-headers pods | awk '{c[$3]++}END{ print NR-c["Running"]}'` -eq 0 ]; do sleep 1; echo "wait all pod running"; kubectl -n vortex get pods; done
- kubectl -n vortex describe daemonset/network-controller-server-tcp
- kubectl -n vortex describe daemonset/network-controller-server-unix
# # Start to test and produce the coverage report
- sudo -E PATH=$PATH TEST_GRPC=1 TEST_PROMETHEUS=1 make src.test-coverage-minikube
#- make src.test-bats

after_success:
- cp build/src/coverage.txt coverage.txt
- bash <(curl -s https://codecov.io/bash)
jobs:
include:
- stage: "Tests"
name: "Unit Test"
script: make pre-build && sudo -E PATH=$PATH TEST_GRPC=1 TEST_PROMETHEUS=1 make src.test-coverage-minikube
after_success:
- cp build/src/coverage.txt coverage.txt
- bash <(curl -s https://codecov.io/bash)
- name: "Integration Tests"
install:
- sudo add-apt-repository ppa:duggan/bats --yes
- sudo apt-get update -q
- sudo apt-get install -qqy jq httpie bats
script:
- make build
- sudo make src.test-bats
10 changes: 7 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,11 @@ src.test-coverage-vagrant:

.PHONY: src.test-bats
src.test-bats:
cd tests; \
bats .;
sed -i.bak "s/localhost:9090/$$(minikube ip):30003/g; s/localhost:27017/$$(minikube ip):31717/g" config/testing.json
echo $$(mminikube ip)
./build/src/cmd/vortex/vortex -config config/testing.json -port 7890 &
@cd tests;\
./test.sh

.PHONY: check-govendor
check-govendor:
Expand All @@ -107,7 +110,8 @@ apps.init-helm:
.PHONY: apps.launch
apps.launch:
helm install --name vortex-foundation --debug --wait --set global.environment=local deploy/helm/foundation
helm install --name vortex-apps --debug --wait --set global.environment=local deploy/helm/apps/
helm install --name vortex-apps --debug --wait --set global.environment=local --set vortex-server.image.tag=$(SERVER_VERSION) deploy/helm/apps/


.PHONY: apps.upgrade
apps.upgrade:
Expand Down
2 changes: 1 addition & 1 deletion config/testing.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
"version": "local",
"logFileName": "access_log"
}
}
}
2 changes: 1 addition & 1 deletion tests/01-multiple-interface/pod.info
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
}
],
"volumes":[],
"restaryPolicy":"Always",
"restartPolicy":"Always",
"capability": true,
"networkType": "custom",
"nodeAffinity": []
Expand Down
16 changes: 8 additions & 8 deletions tests/01-multiple-interface/script.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
load init

@test "Create network" {
http -v --check-status 127.0.0.1:32326/v1/networks < networks.json
http -v --check-status 127.0.0.1:7890/v1/networks < networks.json
[ $? = 0 ]
}

@test "List network" {
run bash -c "http http://127.0.0.1:32326/v1/networks/ 2>/dev/null | jq -r '.[] | select(.name == \"${networkName}\").name'"
run bash -c "http http://127.0.0.1:7890/v1/networks/ 2>/dev/null | jq -r '.[] | select(.name == \"${networkName}\").name'"
[ "$output" = "${networkName}" ]
[ $status = 0 ]
}
Expand All @@ -19,7 +19,7 @@ load init
}

@test "Create Pod" {
http -v --check-status 127.0.0.1:32326/v1/pods < pod.json
http -v --check-status 127.0.0.1:7890/v1/pods < pod.json
[ $? = 0 ]
#Wait the Pod
#jsonpath="{.status.phase}"
Expand All @@ -39,19 +39,19 @@ load init
}

@test "List Pod" {
run bash -c "http http://127.0.0.1:32326/v1/pods/ 2>/dev/null | jq -r '.[] | select(.name == \"${podName}\").name'"
run bash -c "http http://127.0.0.1:7890/v1/pods/ 2>/dev/null | jq -r '.[] | select(.name == \"${podName}\").name'"
[ "$output" = "${podName}" ]
[ $status = 0 ]
}

@test "Delete Pod" {
run bash -c 'http http://127.0.0.1:32326/v1/pods/ 2>/dev/null | jq -r ".[0].id"'
run http DELETE http://127.0.0.1:32326/v1/pods/${output} 2>/dev/null
run bash -c 'http http://127.0.0.1:7890/v1/pods/ 2>/dev/null | jq -r ".[0].id"'
run http DELETE http://127.0.0.1:7890/v1/pods/${output} 2>/dev/null
[ $status = 0 ]
}

@test "Delete Network" {
run bash -c 'http http://127.0.0.1:32326/v1/networks/ 2>/dev/null | jq -r ".[0].id"'
run http DELETE http://127.0.0.1:32326/v1/networks/${output} 2>/dev/null
run bash -c 'http http://127.0.0.1:7890/v1/networks/ 2>/dev/null | jq -r ".[0].id"'
run http DELETE http://127.0.0.1:7890/v1/networks/${output} 2>/dev/null
[ $status = 0 ]
}
2 changes: 1 addition & 1 deletion tests/02-hoet-network/pod.info
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"networks":[
],
"volumes":[],
"restaryPolicy":"Always",
"restartPolicy":"Always",
"capability": true,
"networkType": "host",
"nodeAffinity": []
Expand Down
8 changes: 4 additions & 4 deletions tests/02-hoet-network/script.bats
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
load init

@test "Create Pod" {
http -v --check-status 127.0.0.1:32326/v1/pods < pod.json
http -v --check-status 127.0.0.1:7890/v1/pods < pod.json
[ $? = 0 ]
#Wait the Pod
#jsonpath="{.status.phase}"
Expand All @@ -18,7 +18,7 @@ load init
}

@test "List Pod" {
run bash -c "http http://127.0.0.1:32326/v1/pods/ 2>/dev/null | jq -r '.[] | select(.name == \"${podName}\").name'"
run bash -c "http http://127.0.0.1:7890/v1/pods/ 2>/dev/null | jq -r '.[] | select(.name == \"${podName}\").name'"
[ "$output" = "${podName}" ]
[ $status = 0 ]
}
Expand All @@ -29,7 +29,7 @@ load init
[ "$output" = "true" ]
}
@test "Delete Pod" {
run bash -c 'http http://127.0.0.1:32326/v1/pods/ 2>/dev/null | jq -r ".[0].id"'
run http DELETE http://127.0.0.1:32326/v1/pods/${output} 2>/dev/null
run bash -c 'http http://127.0.0.1:7890/v1/pods/ 2>/dev/null | jq -r ".[0].id"'
run http DELETE http://127.0.0.1:7890/v1/pods/${output} 2>/dev/null
[ $status = 0 ]
}
7 changes: 7 additions & 0 deletions tests/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash
for i in `ls -d */`; do
cd $i
bats .
[ $? -eq 0 ] || exit 1
cd -
done