Skip to content

Commit

Permalink
tests
Browse files Browse the repository at this point in the history
  • Loading branch information
oliver006 committed Sep 9, 2024
1 parent 3cf2d54 commit c9c229c
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 295 deletions.
143 changes: 0 additions & 143 deletions .drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -126,149 +126,6 @@ steps:
- start


- name: test-docker-build
image: plugins/docker
pull: if-not-exists
settings:
mtu: 1200
tags: "test"
dockerfile: ./docker/Dockerfile
repo: oliver006/redis_exporter
target: scratch
dry_run: true
build_args:
- 'TAG=test'
- 'SHA1=${DRONE_COMMIT_SHA}'
- 'GOARCH=amd64'
username:
from_secret: docker_test_user
password:
from_secret: docker_test_pass
when:
event:
- pull_request
- push
- tag
depends_on:
- start

- name: lint
image: golangci/golangci-lint:v1.56.2-alpine
pull: if-not-exists
commands:
- golangci-lint run --tests=false --exclude-use-default --timeout=5m
- golangci-lint run -D=errcheck --exclude-use-default --timeout=5m
when:
event:
- pull_request
- push
- tag
depends_on:
- start

- name: tests
image: golang:1.22
pull: if-not-exists
environment:
GO111MODULE: on
LOG_LEVEL: "info"
commands:
- sleep 15
- make checks
- make test
when:
event:
- pull_request
- push
- tag
depends_on:
- start


- name: mixins
image: golang:1.22
pull: if-not-exists
commands:
- make mixin
when:
event:
- pull_request
- push
- tag
depends_on:
- start


- name: coverage-codecov
image: golang:1.22
pull: if-not-exists
environment:
CODECOV_TOKEN:
from_secret: codecov-token
commands:
- curl -Os https://uploader.codecov.io/latest/linux/codecov
- chmod +x codecov
- ./codecov -t ${CODECOV_TOKEN} -f coverage.txt
when:
event:
- pull_request
- push
- tag
depends_on:
- tests


- name: coverage-coveralls
image: golang:1.22
pull: if-not-exists
environment:
GO111MODULE: on
LOG_LEVEL: "info"
COVERALLS_TOKEN:
from_secret: coveralls-token
commands:
- make upload-coverage
when:
event:
- pull_request
- push
- tag
depends_on:
- tests

# this is just a smoke test if building a few different arch/OS combinations succeeds
- name: build-some-amd64-binaries
image: golang:1.22
pull: if-not-exists
environment:
GO111MODULE: on
LOG_LEVEL: "info"
commands:
- make build-some-amd64-binaries
when:
event:
- pull_request
- push
depends_on:
- start

# this builds the binaries that get uploaded to GH for a release
# docker binaries are build in docker itself via multi-stage Docker files
- name: build-all-binaries
image: golang:1.22
pull: if-not-exists
environment:
GO111MODULE: on
LOG_LEVEL: "info"
commands:
- make build-all-binaries
when:
event:
- tag
depends_on:
- tests


- name: release-docker-image-scratch
image: plugins/docker
pull: if-not-exists
Expand Down
108 changes: 108 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
name: Tests

on:
push:
branches:
- '*'
tags:
- '*'

jobs:
tests:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Set up Docker
uses: docker/setup-buildx-action@v2

- name: Set up Docker Compose
run: sudo apt-get install docker-compose

- name: Start services
run: docker-compose up -d
working-directory: ./

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '1.22'

- name: Install Dependencies
run: go mod tidy

- name: Run tests
env:
GO111MODULE: on
LOG_LEVEL: "info"
run: |
sleep 15
make checks
make test
- name: Upload coverage to Codecov
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
run: |
curl -Os https://uploader.codecov.io/latest/linux/codecov
chmod +x codecov
./codecov -t $CODECOV_TOKEN -f coverage.txt
# - name: Upload coverage to Coveralls
# env:
# COVERALLS_TOKEN: ${{ secrets.COVERALLS_TOKEN }}
# run: make upload-coverage


- name: Coveralls
uses: coverallsapp/github-action@v2

- name: Stop services
run: docker-compose down
working-directory: ./



golangci:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '1.22'

- name: Install Dependencies
run: go mod tidy

- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60
args: "--tests=false"


build-stuff:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Setup Go
uses: actions/setup-go@v3
with:
go-version: '1.22'

- name: Install Dependencies
run: go mod tidy

- name: Build some binaries
run: make build-some-amd64-binaries

- name: Generate mixin
run: make mixin
32 changes: 17 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,20 +31,20 @@ docker-test:
.PHONY: test
test:
contrib/tls/gen-test-certs.sh
TEST_REDIS_URI="redis://redis6:6379" \
TEST_REDIS5_URI="redis://redis5:6383" \
TEST_REDIS6_URI="redis://redis6:6379" \
TEST_VALKEY7_URI="redis://valkey7:6384" \
TEST_REDIS_2_8_URI="redis://redis-2-8:6381" \
TEST_KEYDB01_URI="redis://keydb-01:6401" \
TEST_KEYDB02_URI="redis://keydb-02:6402" \
TEST_PWD_REDIS_URI="redis://:redis-password@pwd-redis5:6380" \
TEST_USER_PWD_REDIS_URI="redis://exporter:exporter-password@pwd-redis6:6390" \
TEST_REDIS_CLUSTER_MASTER_URI="redis://redis-cluster:7000" \
TEST_REDIS_CLUSTER_SLAVE_URI="redis://redis-cluster:7005" \
TEST_REDIS_CLUSTER_PASSWORD_URI="redis://redis-cluster-password:7006" \
TEST_TILE38_URI="redis://tile38:9851" \
TEST_REDIS_SENTINEL_URI="redis://redis-sentinel:26379" \
TEST_REDIS_URI="redis://localhost:16384" \
TEST_REDIS5_URI="redis://localhost:16383" \
TEST_REDIS6_URI="redis://localhost:16379" \
TEST_VALKEY7_URI="redis://localhost:16384" \
TEST_REDIS_2_8_URI="redis://localhost:16381" \
TEST_KEYDB01_URI="redis://localhost:16401" \
TEST_KEYDB02_URI="redis://localhost:16402" \
TEST_PWD_REDIS_URI="redis://:redis-password@localhost:16380" \
TEST_USER_PWD_REDIS_URI="redis://exporter:exporter-password@localhost:16390" \
TEST_REDIS_CLUSTER_MASTER_URI="redis://localhost:17000" \
TEST_REDIS_CLUSTER_SLAVE_URI="redis://localhost:17005" \
TEST_REDIS_CLUSTER_PASSWORD_URI="redis://localhost:17006" \
TEST_TILE38_URI="redis://localhost:19851" \
TEST_REDIS_SENTINEL_URI="redis://localhost:26379" \
go test -v -covermode=atomic -cover -race -coverprofile=coverage.txt -p 1 ./...

.PHONY: lint
Expand All @@ -71,7 +71,9 @@ mixin:
.PHONY: upload-coverage
upload-coverage:
go install github.com/mattn/[email protected]
/go/bin/goveralls -coverprofile=coverage.txt -service=drone.io
which goveralls
echo $PATH
/home/runner/go/bin/goveralls -coverprofile=coverage.txt -service=drone.io



Expand Down
83 changes: 0 additions & 83 deletions contrib/docker-compose-for-tests.yml

This file was deleted.

4 changes: 2 additions & 2 deletions contrib/sample-pwd-file.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"redis://redis6:6379": "",
"redis://pwd-redis5:6380": "redis-password"
"redis://localhost:16379": "",
"redis://localhost:16380": "redis-password"
}
Loading

0 comments on commit c9c229c

Please sign in to comment.