Skip to content

Commit 624c134

Browse files
authored
ci: unit tests
1 parent fde0bf0 commit 624c134

File tree

14 files changed

+122
-166
lines changed

14 files changed

+122
-166
lines changed

.github/workflows/sonarcloud.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ jobs:
2323
with:
2424
experimental: true
2525
- run: mise run dev:lint --no-fail
26+
- run: mise run test:unit --ci
2627
- name: SonarCloud Scan
2728
uses: sonarsource/sonarcloud-github-action@6bbd64e0cb2194e04addb429d669a9ee873eeeef
2829
env:

.gitignore

+3-153
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,6 @@
1-
# Byte-compiled / optimized / DLL files
2-
__pycache__/
3-
*.py[cod]
4-
*$py.class
5-
6-
# C extensions
7-
*.so
8-
9-
# Distribution / packaging
10-
.Python
11-
build/
12-
develop-eggs/
13-
dist/
14-
downloads/
15-
eggs/
16-
.eggs/
17-
lib/
18-
lib64/
19-
parts/
20-
sdist/
21-
var/
22-
wheels/
23-
share/python-wheels/
24-
*.egg-info/
25-
.installed.cfg
26-
*.egg
27-
MANIFEST
28-
29-
# PyInstaller
30-
# Usually these files are written by a python script from a template
31-
# before PyInstaller builds the exe, so as to inject date/other infos into it.
32-
*.manifest
33-
*.spec
34-
35-
# Installer logs
36-
pip-log.txt
37-
pip-delete-this-directory.txt
38-
39-
# Unit test / coverage reports
40-
htmlcov/
41-
.tox/
42-
.nox/
43-
.coverage
44-
.coverage.*
45-
.cache
46-
nosetests.xml
47-
coverage.xml
48-
*.cover
49-
*.py,cover
50-
.hypothesis/
51-
.pytest_cache/
52-
cover/
53-
54-
# Translations
55-
*.mo
56-
*.pot
57-
58-
# Django stuff:
59-
*.log
60-
local_settings.py
61-
db.sqlite3
62-
db.sqlite3-journal
63-
64-
# Flask stuff:
65-
instance/
66-
.webassets-cache
67-
68-
# Scrapy stuff:
69-
.scrapy
70-
71-
# Sphinx documentation
72-
docs/_build/
73-
74-
# PyBuilder
75-
.pybuilder/
76-
target/
77-
78-
# Jupyter Notebook
79-
.ipynb_checkpoints
80-
81-
# IPython
82-
profile_default/
83-
ipython_config.py
84-
85-
# pyenv
86-
# For a library or package, you might want to ignore these files since the code is
87-
# intended to run in multiple environments; otherwise, check them in:
88-
# .python-version
89-
90-
# pipenv
91-
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92-
# However, in case of collaboration, if having platform-specific dependencies or dependencies
93-
# having no cross-platform support, pipenv may install dependencies that don't work, or not
94-
# install all needed dependencies.
95-
#Pipfile.lock
96-
97-
# poetry
98-
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
99-
# This is especially recommended for binary packages to ensure reproducibility, and is more
100-
# commonly ignored for libraries.
101-
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
102-
#poetry.lock
103-
104-
# pdm
105-
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
106-
#pdm.lock
107-
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
108-
# in version control.
109-
# https://pdm.fming.dev/#use-with-ide
110-
.pdm.toml
111-
112-
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
113-
__pypackages__/
114-
115-
# Celery stuff
116-
celerybeat-schedule
117-
celerybeat.pid
118-
119-
# SageMath parsed files
120-
*.sage.py
121-
122-
# Environments
123-
.env
124-
.venv
125-
env/
126-
venv/
127-
ENV/
128-
env.bak/
129-
venv.bak/
130-
131-
# Spyder project settings
132-
.spyderproject
133-
.spyproject
134-
135-
# Rope project settings
136-
.ropeproject
137-
138-
# mkdocs documentation
139-
/site
140-
141-
# mypy
142-
.mypy_cache/
143-
.dmypy.json
144-
dmypy.json
145-
146-
# Pyre type checker
147-
.pyre/
148-
149-
# pytype static type analyzer
150-
.pytype/
151-
152-
# Cython debug symbols
153-
cython_debug/
1+
/build/
2+
/dist/
3+
1544

1555
# PyCharm
1566
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can

.idea/sophrosyne.iml

+2-10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.mise/tasks/build/dist

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/bin/sh
2+
# mise sources=["go.mod", "go.sum", "internal/**/*", "cmd/**/*", "*.go"]
3+
# mise outputs=["dist/sophrosyne", "dist/sophrosyne_linux_amd64", "dist/sophrosyne_linux_arm64]
4+
5+
goos=""
6+
goarch=""
7+
debug=1
8+
ldflags=""
9+
10+
handle_argument() {
11+
echo "Argument '$1' not supported" >&2; exit 1
12+
}
13+
14+
while test "$#" -gt 0; do
15+
case "$1" in
16+
-o) goos="$2"; shift 2;;
17+
-a) goarch="$2"; shift 2;;
18+
19+
--goos=*) goos="${1#*=}"; shift 1;;
20+
--goarch=*) goarch="${1#*=}"; shift 1;;
21+
--goos|--goarch) echo "$1 requires an argument" >&2; exit 1;;
22+
23+
--debug) debug=0; shift 1;;
24+
25+
-*) echo "unknown option: $1" >&2; exit 1;;
26+
*) handle_argument "$1"; shift 1;;
27+
esac
28+
done
29+
30+
if test "$debug" = 1; then
31+
ldflags="-s -w"
32+
fi
33+
34+
if test "$goarch" = ""; then
35+
GOOS="linux" GOARCH="amd64" go build -ldflags="$ldflags" -o dist/sophrosyne_linux_amd64 cmd/sophrosyne/main.go
36+
GOOS="linux" GOARCH="arm64" go build -ldflags="$ldflags" -o dist/sophrosyne_linux_arm64 cmd/sophrosyne/main.go
37+
else
38+
GOOS="$goos" GOARCH="$goarch" go build -ldflags="$ldflags" -o dist/sophrosyne cmd/sophrosyne/main.go
39+
fi

.mise/tasks/build/docker

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/sh
2+
# mise sources=["dist/sophrosyne_linux_arm64", "dist/sophrosyne_linux_amd64"]
3+
# mise outputs=["build/sophrosyne.tar"]
4+
5+
platform="linux/arm64,linux/amd64"
6+
7+
handle_argument() {
8+
echo "Argument '$1' not supported" >&2; exit 1
9+
}
10+
11+
while test "$#" -gt 0; do
12+
case "$1" in
13+
-p) platform="$2"; shift 2;;
14+
15+
--platform=*) platform="${1#*=}"; shift 1;;
16+
--platform) echo "$1 requires an argument" >&2; exit 1;;
17+
18+
-*) echo "unknown option: $1" >&2; exit 1;;
19+
*) handle_argument "$1"; shift 1;;
20+
esac
21+
done
22+
23+
mkdir -p build
24+
25+
docker buildx build --platform="$platform" -o type=oci,dest=build/sophrosyne.tar --tag sophrosyne:0.0.0 .

.mise/tasks/test/integration

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/bin/sh
2+
# mise sources=["go.mod", "go.sum", "internal/**/*", "cmd/**/*", "*.go"]
3+
# mise outputs=[]
4+
5+
go test --tags=integration ./...
6+

.mise/tasks/test/unit

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
# mise sources=["go.mod", "go.sum", "internal/**/*", "cmd/**/*", "*.go"]
3+
# mise outputs=["build/unit_coverage.out", "build/unit_test_report.json"]
4+
5+
ci=1
6+
7+
handle_argument() {
8+
echo "Argument '$1' not supported" >&2; exit 1
9+
}
10+
11+
while test "$#" -gt 0; do
12+
case "$1" in
13+
--ci) ci=0; shift 1;;
14+
15+
-*) echo "unknown option: $1" >&2; exit 1;;
16+
*) handle_argument "$1"; shift 1;;
17+
esac
18+
done
19+
20+
mkdir -p build
21+
22+
if test "$ci" = 0; then
23+
go test -coverprofile build/unit_coverage.out -json ./... > build/unit_test_report.json || true
24+
else
25+
go test -coverprofile build/unit_coverage.out ./...
26+
fi

Dockerfile

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
FROM cgr.dev/chainguard/glibc-dynamic:latest@sha256:6dff3d81e2edaa0ef48ea87b808c34c4b24959169d9ad317333bdda4ec3c4002
2-
COPY --chown=noneroot:noneroot dist/sophrosyne /usr/bin/
1+
FROM --platform=$TARGETPLATFORM cgr.dev/chainguard/glibc-dynamic:latest@sha256:6dff3d81e2edaa0ef48ea87b808c34c4b24959169d9ad317333bdda4ec3c4002
2+
ARG TARGETARCH
3+
USER nonroot
4+
COPY dist/sophrosyne_linux_$TARGETARCH /usr/bin/sophrosyne
35
ENTRYPOINT ["/usr/bin/sophrosyne"]

internal/configProvider/config_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
//go:build !integration
18+
1719
package configProvider
1820

1921
import (

internal/rpc/internal/jsonrpc/jsonrpc_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
//go:build !integration
18+
1719
package jsonrpc
1820

1921
import (

internal/rpc/rpc_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
//go:build !integration
18+
1719
package rpc
1820

1921
import (

internal/validator/validator_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
//go:build !integration
18+
1719
package validator
1820

1921
import (

sonar-project.properties

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
sonar.projectKey=MadsRC_sophrosyne
22
sonar.organization=madsrc
3+
sonar.sources=.
4+
sonar.tests=.
5+
sonar.exclusions=**/*.pb.go,**/*_test.go,tests
6+
sonar.test.inclusions=**/*_test.go
37
sonar.go.golangci-lint.reportPaths=build/report.xml
4-
sonar.exclusions=**/*.pb.go
8+
sonar.go.coverage.reportPaths=build/unit_coverage.out
9+
sonar.go.tests.reportPaths=build/unit_test_report.json

tests/integration/startup_test.go

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
// You should have received a copy of the GNU Affero General Public License
1515
// along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
//go:build integration
18+
1719
package integration
1820

1921
import (

0 commit comments

Comments
 (0)