test: add unit tests and code coverage #892
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI | |
on: | |
release: | |
types: [created] | |
pull_request: | |
types: [opened, synchronize, reopened, ready_for_review, edited] | |
branches: | |
- main | |
paths: | |
- "charts/**" | |
- ".github/workflows/ci.yaml" | |
- "**.go" | |
permissions: read-all | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
golangci: | |
name: lint | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac #v4.0.0 | |
with: | |
submodules: "recursive" | |
- name: Set up Go | |
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe #4.1.0 | |
with: | |
go-version: "1.21" | |
cache: false | |
- name: Run golangci-lint | |
uses: golangci/golangci-lint-action@v3 | |
with: | |
args: -v --config=.golangci.yml | |
unit-test: | |
runs-on: ubuntu-latest | |
env: | |
GOPATH: ${{ github.workspace }}/../go | |
HOME: ${{ github.workspace }}/.. | |
steps: | |
- name: Checkout | |
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac #v4.0.0 | |
with: | |
submodules: "recursive" | |
- name: Set up Go | |
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe #4.1.0 | |
with: | |
go-version: "1.21" | |
cache: false | |
- name: EBPF prerequisites | |
run: | | |
set -x | |
sudo apt update && sudo apt install -y jq pkg-config libelf-dev clang | |
make ebpf | |
- name: Run unit tests | |
run: make unit-test | |
- name: Upload coverage to Codecov | |
uses: codecov/codecov-action@v3 | |
with: | |
token: ${{ secrets.CODECOV_TOKEN }} | |
files: ./coverage.xml | |
verbose: true # optional (default = false) | |
test-k8s: | |
runs-on: ubuntu-latest | |
env: | |
GOPATH: ${{ github.workspace }}/../go | |
HOME: ${{ github.workspace }}/.. | |
steps: | |
- name: Checkout | |
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac #v4.0.0 | |
with: | |
submodules: "recursive" | |
- name: Set up Go | |
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe #4.1.0 | |
with: | |
go-version: "1.21" | |
cache: false | |
- name: Install dependencies | |
run: | | |
set -x | |
# Install required dependencies and tools | |
sudo apt update && sudo apt install -y pkg-config libelf-dev clang | |
go install github.com/mgechev/revive@latest | |
go install honnef.co/go/tools/cmd/staticcheck@latest | |
go install google.golang.org/protobuf/cmd/protoc-gen-go@32051b4f86e54c2142c7c05362c6e96ae3454a1c # @v1.28.0 | |
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@938f6e2f7550e542bd78f3b9e8812665db109e02 # @v1.1.0 | |
- name: Create Kind registry | |
run: | | |
set -x | |
# Create a Kind registry | |
./dev/run-kind-registry.sh | |
- name: Kind Cluster | |
uses: helm/kind-action@dda0770415bac9fc20092cacbc54aa298604d140 #v1.8.0 | |
with: | |
config: "dev/cluster-config.yaml" | |
cluster_name: tarian-testing | |
- name: Testing Kind cluster setup | |
run: | | |
set -x | |
# Verify Kind cluster setup | |
kubectl cluster-info | |
kubectl wait --for=condition=ready pod --all --all-namespaces --timeout=300s | |
kubectl get pods -n kube-system | |
echo "kubectl config current-context:" $(kubectl config current-context) | |
echo "KUBECONFIG env var:" ${KUBECONFIG} | |
- name: Build | |
run: | | |
set -x | |
sudo apt update && sudo apt install -y jq pkg-config libelf-dev clang | |
go install google.golang.org/protobuf/cmd/protoc-gen-go@32051b4f86e54c2142c7c05362c6e96ae3454a1c # @v1.28.0 | |
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@938f6e2f7550e542bd78f3b9e8812665db109e02 # @v1.1.0 | |
make bin/protoc bin/goreleaser | |
bash ./dev/run-kind-registry.sh | |
make ebpf generate | |
./bin/goreleaser release --snapshot --rm-dist | |
make push-local-images | |
cp dist/tarianctl_linux_amd64/tarianctl ./bin/ | |
- name: Install Tarian | |
run: | | |
set -x | |
./bin/tarianctl install --charts ./charts -l debug --agents-values ./dev/values/agents.yaml --server-values ./dev/values/server.yaml | |
continue-on-error: true | |
- name: Wait for pods to be ready | |
id: wait-until-tarian-is-ready | |
run: | | |
set -x | |
# Wait for all pods in the tarian-system namespace to be in the "Ready" state | |
kubectl wait --for=condition=ready pod --all -n tarian-system --timeout=300s | |
continue-on-error: true | |
- name: Run tests | |
id: run-tests | |
if: steps.wait-until-tarian-is-ready.outcome == 'success' | |
run: make k8s-test | |
continue-on-error: true | |
- name: Collect deployment information in case of failure | |
if: steps.wait-until-tarian-is-ready.outcome != 'success' || steps.run-tests.outcome != 'success' | |
run: | | |
set -x | |
# Collect logs and information for debugging in case of failure | |
kubectl get pods -n tarian-system | |
echo "======================================================================================================================" | |
kubectl describe pods -n tarian-system | |
echo "======================================================================================================================" | |
kubectl logs -n tarian-system deploy/tarian-server | |
echo "======================================================================================================================" | |
kubectl logs -n tarian-system deploy/tarian-cluster-agent | |
echo "======================================================================================================================" | |
kubectl logs -n tarian-system deploy/tarian-controller-manager | |
echo "======================================================================================================================" | |
kubectl logs -n tarian-system daemonsets/tarian-node-agent | |
echo "======================================================================================================================" | |
exit 1 | |
test-e2e: | |
runs-on: ubuntu-latest | |
env: | |
GOPATH: ${{ github.workspace }}/../go | |
HOME: ${{ github.workspace }}/.. | |
steps: | |
- name: Checkout | |
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac #v4.0.0 | |
with: | |
submodules: "recursive" | |
- name: Set up Go | |
uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe #4.1.0 | |
with: | |
go-version: "1.21" | |
cache: false | |
- name: Start containers | |
run: docker-compose up -d | |
- name: Run end-to-end tests | |
id: run-e2e-tests | |
run: | | |
set -x | |
sudo apt update && sudo apt install -y pkg-config libelf-dev clang | |
go install github.com/mgechev/revive@latest | |
go install honnef.co/go/tools/cmd/staticcheck@latest | |
go install google.golang.org/protobuf/cmd/protoc-gen-go@32051b4f86e54c2142c7c05362c6e96ae3454a1c # @v1.28.0 | |
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@938f6e2f7550e542bd78f3b9e8812665db109e02 # @v1.1.0 | |
make bin/protoc | |
make build | |
make e2e-test | |
continue-on-error: true | |
- name: Collect logs in case of failure | |
if: steps.run-e2e-tests.outcome != 'success' | |
run: | | |
set -x | |
echo "======================================================================================================================" | |
docker-compose logs | |
echo "======================================================================================================================" | |
exit 1 |