Skip to content

Commit

Permalink
ci/gha: run tests as root
Browse files Browse the repository at this point in the history
Some tests require root -- give it to them.

Unfortunately there's no sudo on Windows, so add some ifs.

[v2: add -E PATH=$PATH, otherwise sudo will use stock go]
[v3: add ~/.cache fixup]
[v4: add sudotest make target and use it]

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Feb 25, 2021
1 parent ce49bfe commit 89b55da
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@ jobs:
- name: Cross build
if: ${{ runner.os == 'Linux' }}
run: make cross
- name: Test
- name: Test (!windows)
if: ${{ runner.os != 'Windows' }}
run: make sudotest
- name: Test (windows)
if: ${{ runner.os == 'Windows' }}
run: make test

# some features, like openat2, require a newer kernel
Expand All @@ -39,4 +43,4 @@ jobs:
run: ssh default 'sh -exc "uname -a && df -T"'

- name: tests
run: ssh default 'cd /vagrant && sudo -E PATH=$PATH make test'
run: ssh default 'cd /vagrant && make sudotest'
9 changes: 9 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ PACKAGES ?= mountinfo mount symlink
BINDIR ?= _build/bin
CROSS ?= linux/arm linux/arm64 linux/ppc64le linux/s390x \
freebsd/amd64 openbsd/amd64 darwin/amd64 darwin/arm64 windows/amd64
SUDO ?= sudo -E PATH=$$PATH

.PHONY: all
all: lint test cross
Expand All @@ -13,6 +14,14 @@ test:
(cd $$p && go test -v .); \
done

.PHONY: sudotest
sudotest:
$(SUDO) -n true # check that sudo works without a password
for p in $(PACKAGES); do \
(cd $$p && go test -c && \
$(SUDO) ./$${p}.test -test.v); \
done

.PHONY: lint
lint: $(BINDIR)/golangci-lint
$(BINDIR)/golangci-lint version
Expand Down

0 comments on commit 89b55da

Please sign in to comment.