1
0
Fork 0
mirror of synced 2024-06-01 06:41:11 -04:00

Merge pull request #282 from erijo/testenv

This commit is contained in:
Tim Byrne 2020-12-30 14:28:03 -06:00
commit 1f82ccc2b9
No known key found for this signature in database
GPG key ID: 14DB4FC2465A4B12
3 changed files with 32 additions and 26 deletions

View file

@ -10,7 +10,4 @@ jobs:
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
- name: Tests - name: Tests
run: >- run: make test
docker run -t --rm
-v "$PWD:/yadm:ro"
yadm/testbed:2020-12-29

1
.gitignore vendored
View file

@ -2,5 +2,6 @@
.jekyll-metadata .jekyll-metadata
.pytest_cache .pytest_cache
.sass-cache .sass-cache
.testyadm
_site _site
testenv testenv

View file

@ -26,14 +26,15 @@ usage:
@echo ' HEAD revision of yadm will be used unless "version" is' @echo ' HEAD revision of yadm will be used unless "version" is'
@echo ' specified. "version" can be set to any commit, branch, tag, etc.' @echo ' specified. "version" can be set to any commit, branch, tag, etc.'
@echo ' The targeted "version" will be retrieved from the repo, and' @echo ' The targeted "version" will be retrieved from the repo, and'
@echo ' linked into the container as a local volume.' @echo ' linked into the container as a local volume. Setting version to'
@echo ' "local" uses yadm from the current working tree.'
@echo @echo
@echo ' make scripthost [version=VERSION]' @echo ' make scripthost [version=VERSION]'
@echo ' - Create an ephemeral container for demonstrating a bug. After' @echo ' - Create an ephemeral container for demonstrating a bug. After'
@echo ' exiting the shell, a log of the commands used to illustrate the' @echo ' exiting the shell, a log of the commands used to illustrate the'
@echo ' problem will be written to the file "script.txt". This file can' @echo ' problem will be written to the file "script.txt". This file can'
@echo ' be useful to developers to make a repeatable test for the' @echo ' be useful to developers to make a repeatable test for the'
@echo ' problem.' @echo ' problem. The version parameter works as for "testhost" above.'
@echo @echo
@echo 'LINTING' @echo 'LINTING'
@echo @echo
@ -82,7 +83,7 @@ usage:
# Make it possible to run make specifying a py.test test file # Make it possible to run make specifying a py.test test file
.PHONY: $(PYTESTS) .PHONY: $(PYTESTS)
$(PYTESTS): $(PYTESTS):
@$(MAKE) test testargs="-k $@ $(testargs)" @$(MAKE) test testargs="$@ $(testargs)"
%.py: %.py:
@$(MAKE) test testargs="-k $@ $(testargs)" @$(MAKE) test testargs="-k $@ $(testargs)"
@ -94,46 +95,49 @@ test:
py.test -v $(testargs); \ py.test -v $(testargs); \
else \ else \
$(MAKE) -s require-docker && \ $(MAKE) -s require-docker && \
docker run --rm -it -v "$(CURDIR):/yadm:ro" $(IMAGE) make test testargs="$(testargs)"; \ docker run \
--rm -t$(shell test -t 0 && echo i) \
-v "$(CURDIR):/yadm:ro" \
$(IMAGE) \
make test testargs="$(testargs)"; \
fi fi
.PHONY: testhost .PHONY: .testyadm
testhost: version ?= HEAD .testyadm: version ?= HEAD
testhost: require-docker .testyadm:
@rm -rf /tmp/testhost @echo "Using yadm version=\"$(version)\""
@if [ "$(version)" = "local" ]; then \ @if [ "$(version)" = "local" ]; then \
cp -f yadm /tmp/testhost; \ cp -f yadm $@; \
else \ else \
git show $(version):yadm > /tmp/testhost; \ git show $(version):yadm > $@; \
fi fi
@chmod a+x /tmp/testhost @chmod a+x $@
@echo Starting testhost version=\"$(version)\"
.PHONY: testhost
testhost: require-docker .testyadm
@echo "Starting testhost"
@docker run \ @docker run \
-w /root \ -w /root \
--hostname testhost \ --hostname testhost \
--rm -it \ --rm -it \
-v "/tmp/testhost:/bin/yadm:ro" \ -v "$(CURDIR)/.testyadm:/bin/yadm:ro" \
$(IMAGE) \ $(IMAGE) \
bash -l bash -l
.PHONY: scripthost .PHONY: scripthost
scripthost: version ?= HEAD scripthost: require-docker .testyadm
scripthost: require-docker @echo "Starting scripthost \(recording script\)"
@rm -rf /tmp/testhost
@git show $(version):yadm > /tmp/testhost
@chmod a+x /tmp/testhost
@echo Starting scripthost version=\"$(version)\" \(recording script\)
@printf '' > script.gz @printf '' > script.gz
@docker run \ @docker run \
-w /root \ -w /root \
--hostname scripthost \ --hostname scripthost \
--rm -it \ --rm -it \
-v "$$PWD/script.gz:/script.gz:rw" \ -v "$(CURDIR)/script.gz:/script.gz:rw" \
-v "/tmp/testhost:/bin/yadm:ro" \ -v "$(CURDIR)/.testyadm:/bin/yadm:ro" \
$(IMAGE) \ $(IMAGE) \
bash -c "script /tmp/script -q -c 'bash -l'; gzip < /tmp/script > /script.gz" bash -c "script /tmp/script -q -c 'bash -l'; gzip < /tmp/script > /script.gz"
@echo @echo
@echo "Script saved to $$PWD/script.gz" @echo "Script saved to $(CURDIR)/script.gz"
.PHONY: testenv .PHONY: testenv
@ -143,6 +147,10 @@ testenv:
python3 -m venv --clear testenv python3 -m venv --clear testenv
testenv/bin/pip3 install --upgrade pip setuptools testenv/bin/pip3 install --upgrade pip setuptools
testenv/bin/pip3 install --upgrade -r test/requirements.txt; testenv/bin/pip3 install --upgrade -r test/requirements.txt;
@for v in $$(sed -rn -e 's:.*/yadm-([0-9.]+)$$:\1:p' test/Dockerfile); do \
git show $$v:yadm > testenv/bin/yadm-$$v; \
chmod +x testenv/bin/yadm-$$v; \
done
@echo @echo
@echo 'To activate this test environment type:' @echo 'To activate this test environment type:'
@echo ' source testenv/bin/activate' @echo ' source testenv/bin/activate'