Add test containers
This commit is contained in:
parent
ca20c11962
commit
7d89f51eac
9 changed files with 169 additions and 2 deletions
17
containers/Containerfile.test
Normal file
17
containers/Containerfile.test
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
FROM debian:trixie
|
||||
MAINTAINER Juno Takano juno@jutty.dev
|
||||
|
||||
RUN apt-get --update install -y sudo
|
||||
RUN useradd -mU sudoer
|
||||
RUN echo "sudoer ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
|
||||
|
||||
USER sudoer
|
||||
WORKDIR /home/sudoer
|
||||
RUN mkdir -p .config/tori
|
||||
RUN touch .config/tori/tori.conf
|
||||
RUN echo "su_command = sudo" > .config/tori/tori.conf
|
||||
|
||||
COPY tori /usr/local/bin/tori
|
||||
COPY test.sh /usr/local/bin/test.sh
|
||||
|
||||
CMD test.sh
|
||||
20
containers/Containerfile.test-clean
Normal file
20
containers/Containerfile.test-clean
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
FROM debian:trixie
|
||||
MAINTAINER Juno Takano juno@jutty.dev
|
||||
|
||||
# RUN apt-get --update install -y sudo
|
||||
# RUN useradd -mU sudoer
|
||||
# RUN echo "sudoer ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers
|
||||
|
||||
RUN mkdir -p /root/.config/tori
|
||||
RUN touch /root/.config/tori/tori.conf
|
||||
|
||||
# USER sudoer
|
||||
# WORKDIR /home/sudoer
|
||||
# RUN mkdir -p .config/tori
|
||||
# RUN touch .config/tori/tori.conf
|
||||
# RUN echo "su_command = sudo" > .config/tori/tori.conf
|
||||
|
||||
COPY tori /usr/local/bin/tori
|
||||
COPY test-clean.sh /usr/local/bin/test-clean.sh
|
||||
|
||||
CMD test-clean.sh
|
||||
6
containers/build-run.sh
Executable file
6
containers/build-run.sh
Executable file
|
|
@ -0,0 +1,6 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
set -eu
|
||||
|
||||
./build.sh "$1" && clear
|
||||
./run.sh "$1"
|
||||
27
containers/build.sh
Executable file
27
containers/build.sh
Executable file
|
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
set -eu
|
||||
suffix=$(printf '%s' "$1" | sed 's/.*\.//')
|
||||
binary=tori
|
||||
tag="$binary:$suffix"
|
||||
shift
|
||||
|
||||
if podman container exists "$tag"; then
|
||||
podman stop --time 3 "$tag"
|
||||
fi
|
||||
|
||||
if ! [ -f "../target/debug/$binary" ]; then
|
||||
cd ..
|
||||
cargo build
|
||||
cd -
|
||||
fi
|
||||
|
||||
cp -v ../target/debug/$binary $binary
|
||||
|
||||
podman build \
|
||||
--tag "$tag" \
|
||||
-f "Containerfile.$suffix" "$@"
|
||||
|
||||
if [ -f $binary ]; then
|
||||
rm -v $binary
|
||||
fi
|
||||
16
containers/run.sh
Executable file
16
containers/run.sh
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
set -eu
|
||||
suffix=$(printf '%s' "$1" | sed 's/.*\.//')
|
||||
binary=tori
|
||||
name="$binary-$suffix"
|
||||
tag="$binary:$suffix"
|
||||
shift
|
||||
|
||||
podman run \
|
||||
--replace \
|
||||
--name "$name" \
|
||||
--publish 3008:80 \
|
||||
--init \
|
||||
"$@" \
|
||||
"$tag"
|
||||
38
containers/test-clean.sh
Executable file
38
containers/test-clean.sh
Executable file
|
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
set -eu
|
||||
|
||||
info() { printf ' [info] %b\n' "$1"; }
|
||||
announce() { printf ' [test] %b\n' "$1"; }
|
||||
ok() { printf " [ OK ] %b\n" "$1"; }
|
||||
fail() { printf " [FAIL] %b\n" "$1"; exit 1; }
|
||||
|
||||
try() {
|
||||
actual="$1"
|
||||
expected="$2"
|
||||
fail_message="${3:-}"
|
||||
ok_message="${4:-}"
|
||||
|
||||
if [ "$actual" = "$expected" ]; then
|
||||
ok "$ok_message"
|
||||
else
|
||||
fail "Expected <$expected>, got <$actual> $fail_message"
|
||||
fi
|
||||
}
|
||||
|
||||
announce "Fresh install has no manually installed packages"
|
||||
tori_manual=$(tori manual)
|
||||
try "$tori_manual" ""
|
||||
|
||||
info "Updating apt packages"
|
||||
apt-get update >/dev/null
|
||||
|
||||
announce "Manually installed package is the only package in 'tori manual'"
|
||||
apt-get install -y figlet >/dev/null 2>&1
|
||||
tori_manual=$(tori manual)
|
||||
try "$tori_manual" figlet
|
||||
|
||||
announce "Manually installed packages are the only packages in 'tori manual'"
|
||||
apt-get install -y sudo >/dev/null 2>&1
|
||||
tori_manual=$(tori manual | sort)
|
||||
try "$tori_manual" "$(printf 'figlet\nsudo')"
|
||||
40
containers/test.sh
Executable file
40
containers/test.sh
Executable file
|
|
@ -0,0 +1,40 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
set -eu
|
||||
|
||||
info() { printf ' [info] %b\n' "$1"; }
|
||||
announce() { printf ' [test] %b\n' "$1"; }
|
||||
ok() { printf " [ OK ] %b\n" "$1"; }
|
||||
fail() { printf " [FAIL] %b\n" "$1"; exit 1; }
|
||||
|
||||
try() {
|
||||
actual="$1"
|
||||
expected="$2"
|
||||
operator="${3:-=}"
|
||||
fail_message="${3:-}"
|
||||
ok_message="${4:-}"
|
||||
|
||||
# shellcheck disable=1073,1072,1009
|
||||
if [ "$actual" "$operator" "$expected" ]; then
|
||||
ok "$ok_message"
|
||||
else
|
||||
fail_message=${fail_message:+": $fail_message"}
|
||||
fail "Expected <$expected>, got <$actual>$fail_message"
|
||||
fi
|
||||
}
|
||||
|
||||
announce "sudo works"
|
||||
whoami=$(whoami)
|
||||
sudo_whoami=$(sudo whoami)
|
||||
echo try "$whoami" "$sudo_whoami" !=
|
||||
try "$whoami" "$sudo_whoami" !=
|
||||
echo try "$sudo_whoami" root
|
||||
try "$sudo_whoami" root
|
||||
|
||||
info "Updating apt packages"
|
||||
sudo apt-get update >/dev/null
|
||||
|
||||
announce "Manually installed packages are the only packages in 'tori manual'"
|
||||
sudo apt-get install -y sudo >/dev/null 2>&1
|
||||
tori_manual=$(tori manual | sort)
|
||||
try "$tori_manual" "sudo"
|
||||
|
|
@ -81,7 +81,10 @@ fn get_root() -> PathBuf {
|
|||
root
|
||||
} else {
|
||||
if let Ok(user) = std::env::var("USER") {
|
||||
PathBuf::from("/home").join(user).join(".config").join("tori")
|
||||
PathBuf::from("/home")
|
||||
.join(user)
|
||||
.join(".config")
|
||||
.join("tori")
|
||||
} else {
|
||||
eprintln!("Failed to determine home directory");
|
||||
PathBuf::from("/etc/tori")
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use crate::{
|
|||
conf::Configuration,
|
||||
log::elog,
|
||||
os::{
|
||||
OperatingSystem, Kind,
|
||||
Kind, OperatingSystem,
|
||||
pkg::{self, Package, PackagerVariant, Packages},
|
||||
},
|
||||
run::{Command, executor::read},
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue