diff --git a/.dockerignore b/.dockerignore index 9d68dd259..7954bb4b8 100644 --- a/.dockerignore +++ b/.dockerignore @@ -4,7 +4,8 @@ obj-x86_64-linux-gnu/ obj-aarch64-linux-gnu/ obj-arm-linux-gnueabihf/ obj-i686-linux-gnu/ -unit.out +unit-test.cov +system-test.cov aptly.test build/ dpkgs/ diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 31aa2ab6d..eb42a003a 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -89,12 +89,12 @@ jobs: AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} run: | sudo mkdir -p /srv ; sudo chown runner /srv - COVERAGE_DIR=${{ runner.temp }} make system-test + make system-test - name: "Merge Code Coverage" run: | go install github.com/wadey/gocovmerge@v0.0.0-20160331181800-b5bfa59ec0ad - ~/go/bin/gocovmerge unit.out ${{ runner.temp }}/*.out > coverage.txt + ~/go/bin/gocovmerge unit-test.cov system-test.cov > coverage.txt - name: "Upload Code Coverage" uses: codecov/codecov-action@v2 diff --git a/.gitignore b/.gitignore index f23337518..944086d65 100644 --- a/.gitignore +++ b/.gitignore @@ -2,7 +2,8 @@ *.o *.a *.so -unit.out +unit-test.cov +system-test.cov # Folders _obj diff --git a/Makefile b/Makefile index dc1973d16..dd37deec9 100644 --- a/Makefile +++ b/Makefile @@ -3,7 +3,6 @@ VERSION=$(shell make -s version) PYTHON?=python3 BINPATH?=$(GOPATH)/bin GOLANGCI_LINT_VERSION=v2.0.2 # version supporting go 1.24 -COVERAGE_DIR?=$(shell mktemp -d) GOOS=$(shell go env GOHOSTOS) GOARCH=$(shell go env GOHOSTARCH) @@ -15,12 +14,16 @@ export TZ=UTC # Unit Tests and some sysmte tests rely on expired certificates, turn back the time export TEST_FAKETIME := 2025-01-02 03:04:05 +ifeq ($(origin COVERAGE_DIR), undefined) +COVERAGE_DIR := $(shell mktemp -d) +endif + # run with 'COVERAGE_SKIP=1' to skip coverage checks during system tests ifeq ($(COVERAGE_SKIP),1) COVERAGE_ARG_BUILD := COVERAGE_ARG_TEST := --coverage-skip else -COVERAGE_ARG_BUILD := -coverpkg="./..." +COVERAGE_ARG_BUILD := -coverpkg=github.com/aptly-dev/aptly/... COVERAGE_ARG_TEST := --coverage-dir $(COVERAGE_DIR) endif @@ -107,13 +110,16 @@ test: prepare swagger etcd-install ## Run unit tests (add TEST=regex to specify @echo "\e[33m\e[1mStarting etcd ...\e[0m" @mkdir -p /tmp/aptly-etcd-data; system/t13_etcd/start-etcd.sh > /tmp/aptly-etcd-data/etcd.log 2>&1 & @echo "\e[33m\e[1mRunning go test ...\e[0m" - faketime "$(TEST_FAKETIME)" go test -v ./... -gocheck.v=true -check.f "$(TEST)" -coverprofile=unit.out; echo $$? > .unit-test.ret + faketime "$(TEST_FAKETIME)" go test -v ./... -gocheck.v=true -check.f "$(TEST)" -coverprofile=unit-test.cov; echo $$? > .unit-test.ret @echo "\e[33m\e[1mStopping etcd ...\e[0m" @pid=`cat /tmp/etcd.pid`; kill $$pid @rm -f /tmp/aptly-etcd-data/etcd.log @ret=`cat .unit-test.ret`; if [ "$$ret" = "0" ]; then echo "\n\e[32m\e[1mUnit Tests SUCCESSFUL\e[0m"; else echo "\n\e[31m\e[1mUnit Tests FAILED\e[0m"; fi; rm -f .unit-test.ret; exit $$ret + @go tool cover -func=unit-test.cov + system-test: prepare swagger etcd-install ## Run system tests + @test -f $(BINPATH)/gocovmerge || GOOS= GOARCH= go install github.com/wadey/gocovmerge@latest # build coverage binary go test -v $(COVERAGE_ARG_BUILD) -c -tags testruncli # Download fixture-db, fixture-pool, etcd.db @@ -122,6 +128,9 @@ system-test: prepare swagger etcd-install ## Run system tests test -f ~/etcd.db || (curl -o ~/etcd.db.xz http://repo.aptly.info/system-tests/etcd.db.xz && xz -d ~/etcd.db.xz) # Run system tests PATH=$(BINPATH)/:$(PATH) FORCE_COLOR=1 $(PYTHON) system/run.py --long $(COVERAGE_ARG_TEST) $(CAPTURE_ARG) $(TEST) + PATH=$(BINPATH)/:$(PATH) gocovmerge $(COVERAGE_DIR)/*.out > system-test.cov + rm -f $(COVERAGE_DIR)/*.out + go tool cover -func=system-test.cov bench: @echo "\e[33m\e[1mRunning benchmark ...\e[0m" @@ -237,7 +246,7 @@ clean: ## remove local build and module cache test ! -e .go || find .go/ -type d ! -perm -u=w -exec chmod u+w {} \; rm -rf .go/ rm -rf build/ obj-*-linux-gnu* tmp/ - rm -f unit.out aptly.test VERSION docs/docs.go docs/swagger.json docs/swagger.yaml docs/swagger.conf + rm -f unit-test.cov system-test.cov aptly.test VERSION docs/docs.go docs/swagger.json docs/swagger.yaml docs/swagger.conf find system/ -type d -name __pycache__ -exec rm -rf {} \; 2>/dev/null || true .PHONY: help man prepare swagger version binaries build docker-release docker-system-test docker-unit-test docker-lint docker-build docker-image docker-man docker-shell docker-serve clean releasetype dpkg serve flake8 diff --git a/api/repos.go b/api/repos.go index ff496f2cd..c5e8b6036 100644 --- a/api/repos.go +++ b/api/repos.go @@ -3,6 +3,7 @@ package api import ( "fmt" "net/http" + "net/url" "os" "path/filepath" "sort" @@ -195,7 +196,11 @@ func apiReposEdit(c *gin.Context) { collectionFactory := context.NewCollectionFactory() collection := collectionFactory.LocalRepoCollection() - name := c.Params.ByName("name") + name, err := url.PathUnescape(c.Params.ByName("name")) + if err != nil { + AbortWithJSONError(c, 400, err) + return + } repo, err := collection.ByName(name) if err != nil { AbortWithJSONError(c, 404, err) diff --git a/system/t06_publish/PublishSnapshot43Test_gold b/system/t06_publish/PublishSnapshot43Test_gold index 8738ec92f..0ffddaf32 100644 --- a/system/t06_publish/PublishSnapshot43Test_gold +++ b/system/t06_publish/PublishSnapshot43Test_gold @@ -5,7 +5,7 @@ Signing file 'Release' with gpg, please enter your passphrase when prompted: Clearsigning file 'Release' with gpg, please enter your passphrase when prompted: Snapshot snap43 has been successfully published. -Please setup your webserver to serve directory '/home/runner/.aptly/public' with autoindexing. +Please setup your webserver to serve directory '${HOME}/.aptly/public' with autoindexing. Now you can add following line to apt sources: deb http://your-server/ maverick main Don't forget to add your GPG key to apt with apt-key. diff --git a/system/testout.py b/system/testout.py index f7dc134d8..d63d6316a 100644 --- a/system/testout.py +++ b/system/testout.py @@ -3,7 +3,7 @@ class TestOut: def __init__(self): - self.tmp_file = tempfile.NamedTemporaryFile(delete=False) + self.tmp_file = tempfile.NamedTemporaryFile(delete=True) self.read_pos = 0 def fileno(self):