[chore]: fix automated tests (#2506)

* fix automated tests

* automated test gh workflow

* rename workflow

* ignore test that relies on physical hardware

* use HOME env var when relevant

* optimize

* fix test
This commit is contained in:
Aiden McClelland
2023-11-10 14:15:47 -07:00
committed by GitHub
parent 521014cd1f
commit b7b022cc7b
10 changed files with 97 additions and 20 deletions

31
.github/workflows/test.yaml vendored Normal file
View File

@@ -0,0 +1,31 @@
name: Automated Tests
on:
push:
branches:
- master
- next/*
pull_request:
branches:
- master
- next/*
env:
NODEJS_VERSION: "18.15.0"
ENVIRONMENT: dev-unstable
jobs:
test:
name: Run Automated Tests
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
submodules: recursive
- uses: actions/setup-node@v3
with:
node-version: ${{ env.NODEJS_VERSION }}
- name: Build And Run Tests
run: make test

View File

@@ -15,7 +15,7 @@ EMBASSY_SRC := backend/startd.service $(BUILD_SRC)
COMPAT_SRC := $(shell git ls-files system-images/compat/)
UTILS_SRC := $(shell git ls-files system-images/utils/)
BINFMT_SRC := $(shell git ls-files system-images/binfmt/)
BACKEND_SRC := $(shell git ls-files backend) $(shell git ls-files --recurse-submodules patch-db) $(shell git ls-files libs) frontend/dist/static
BACKEND_SRC := $(shell git ls-files backend) $(shell git ls-files --recurse-submodules patch-db) $(shell git ls-files libs) frontend/dist/static frontend/patchdb-ui-seed.json $(GIT_HASH_FILE)
FRONTEND_SHARED_SRC := $(shell git ls-files frontend/projects/shared) $(shell ls -p frontend/ | grep -v / | sed 's/^/frontend\//g') frontend/node_modules frontend/config.json patch-db/client/dist frontend/patchdb-ui-seed.json
FRONTEND_UI_SRC := $(shell git ls-files frontend/projects/ui)
FRONTEND_SETUP_WIZARD_SRC := $(shell git ls-files frontend/projects/setup-wizard)
@@ -48,7 +48,7 @@ endif
.DELETE_ON_ERROR:
.PHONY: all metadata install clean format sdk snapshots frontends ui backend reflash deb $(IMAGE_TYPE) squashfs sudo wormhole docker-buildx
.PHONY: all metadata install clean format sdk snapshots frontends ui backend reflash deb $(IMAGE_TYPE) squashfs sudo wormhole test
all: $(ALL_TARGETS)
@@ -82,6 +82,10 @@ format:
cd backend && cargo +nightly fmt
cd libs && cargo +nightly fmt
test: $(BACKEND_SRC) $(ENVIRONMENT_FILE)
cd backend && cargo build && cargo test
cd libs && cargo test
sdk:
cd backend/ && ./install-sdk.sh
@@ -164,20 +168,20 @@ upload-ota: results/$(BASENAME).squashfs
build/lib/depends build/lib/conflicts: build/dpkg-deps/*
build/dpkg-deps/generate.sh
system-images/compat/docker-images/$(ARCH).tar: $(COMPAT_SRC) backend/Cargo.lock | docker-buildx
system-images/compat/docker-images/$(ARCH).tar: $(COMPAT_SRC) backend/Cargo.lock
cd system-images/compat && make docker-images/$(ARCH).tar && touch docker-images/$(ARCH).tar
system-images/utils/docker-images/$(ARCH).tar: $(UTILS_SRC) | docker-buildx
system-images/utils/docker-images/$(ARCH).tar: $(UTILS_SRC)
cd system-images/utils && make docker-images/$(ARCH).tar && touch docker-images/$(ARCH).tar
system-images/binfmt/docker-images/$(ARCH).tar: $(BINFMT_SRC) | docker-buildx
system-images/binfmt/docker-images/$(ARCH).tar: $(BINFMT_SRC)
cd system-images/binfmt && make docker-images/$(ARCH).tar && touch docker-images/$(ARCH).tar
snapshots: libs/snapshot_creator/Cargo.toml
cd libs/ && ./build-v8-snapshot.sh
cd libs/ && ./build-arm-v8-snapshot.sh
$(EMBASSY_BINS): $(BACKEND_SRC) $(ENVIRONMENT_FILE) $(GIT_HASH_FILE) frontend/patchdb-ui-seed.json
$(EMBASSY_BINS): $(BACKEND_SRC) $(ENVIRONMENT_FILE)
cd backend && ARCH=$(ARCH) ./build-prod.sh
touch $(EMBASSY_BINS)

View File

@@ -169,6 +169,9 @@ zeroize = "1.6.0"
[profile.test]
opt-level = 3
[profile.dev]
opt-level = 3
[profile.dev.package.backtrace]
opt-level = 3

View File

@@ -4,7 +4,7 @@ use serde_json::Value;
use crate::procedure::js_scripts::ExecuteArgs;
use crate::s9pk::manifest::PackageId;
use crate::util::serde::{display_serializable, parse_stdin_deserializable};
use crate::util::serde::{display_serializable, parse_stdin_deserializable, IoFormat};
use crate::version::{Current, VersionT};
use crate::Error;
@@ -23,6 +23,9 @@ fn deno_api() -> Result<(), Error> {
#[command(cli_only, display(display_serializable))]
async fn execute(
#[arg(stdin, parse(parse_stdin_deserializable))] arg: ExecuteArgs,
#[allow(unused_variables)]
#[arg(long = "format")]
format: Option<IoFormat>,
) -> Result<Result<Value, (i32, String)>, Error> {
let ExecuteArgs {
procedure,
@@ -41,6 +44,9 @@ async fn execute(
#[command(cli_only, display(display_serializable))]
async fn sandbox(
#[arg(stdin, parse(parse_stdin_deserializable))] arg: ExecuteArgs,
#[allow(unused_variables)]
#[arg(long = "format")]
format: Option<IoFormat>,
) -> Result<Result<Value, (i32, String)>, Error> {
let ExecuteArgs {
procedure,

View File

@@ -32,19 +32,19 @@ async fn setup_or_init(cfg_path: Option<PathBuf>) -> Result<Option<Shutdown>, Er
.arg("-sf")
.arg("/usr/lib/startos/scripts/fake-apt")
.arg("/usr/local/bin/apt")
.invoke(crate::ErrorKind::OpenSsh)
.invoke(crate::ErrorKind::Filesystem)
.await?;
Command::new("ln")
.arg("-sf")
.arg("/usr/lib/startos/scripts/fake-apt")
.arg("/usr/local/bin/apt-get")
.invoke(crate::ErrorKind::OpenSsh)
.invoke(crate::ErrorKind::Filesystem)
.await?;
Command::new("ln")
.arg("-sf")
.arg("/usr/lib/startos/scripts/fake-apt")
.arg("/usr/local/bin/aptitude")
.invoke(crate::ErrorKind::OpenSsh)
.invoke(crate::ErrorKind::Filesystem)
.await?;
Command::new("make-ssl-cert")

View File

@@ -684,6 +684,7 @@ impl TorControl {
}
#[tokio::test]
#[ignore]
async fn test() {
let mut conn = torut::control::UnauthenticatedConn::new(
TcpStream::connect(SocketAddr::from(([127, 0, 0, 1], 9051)))

View File

@@ -81,8 +81,12 @@ impl JsProcedure {
_gid: ProcessGroupId,
_rpc_client: Option<Arc<UnixRpcClient>>,
) -> Result<Result<O, (i32, String)>, Error> {
Command::new("start-deno")
.arg("execute")
#[cfg(not(test))]
let mut cmd = Command::new("start-deno");
#[cfg(test)]
let mut cmd = test_start_deno_command().await?;
cmd.arg("execute")
.input(Some(&mut std::io::Cursor::new(IoFormat::Json.to_vec(
&ExecuteArgs {
procedure: self.clone(),
@@ -111,8 +115,12 @@ impl JsProcedure {
timeout: Option<Duration>,
name: ProcedureName,
) -> Result<Result<O, (i32, String)>, Error> {
Command::new("start-deno")
.arg("sandbox")
#[cfg(not(test))]
let mut cmd = Command::new("start-deno");
#[cfg(test)]
let mut cmd = test_start_deno_command().await?;
cmd.arg("sandbox")
.input(Some(&mut std::io::Cursor::new(IoFormat::Json.to_vec(
&ExecuteArgs {
procedure: self.clone(),
@@ -212,6 +220,26 @@ fn unwrap_known_error<O: DeserializeOwned>(
}
}
#[cfg(test)]
async fn test_start_deno_command() -> Result<Command, Error> {
Command::new("cargo")
.arg("build")
.invoke(ErrorKind::Unknown)
.await?;
if tokio::fs::metadata("target/debug/start-deno")
.await
.is_err()
{
Command::new("ln")
.arg("-rsf")
.arg("target/debug/startbox")
.arg("target/debug/start-deno")
.invoke(crate::ErrorKind::Filesystem)
.await?;
}
Ok(Command::new("target/debug/start-deno"))
}
#[tokio::test]
async fn js_action_execute() {
let js_action = JsProcedure { args: vec![] };

View File

@@ -179,5 +179,7 @@ impl<'de> Deserialize<'de> for NoOutput {
#[test]
fn test_deser_no_output() {
serde_json::from_str::<NoOutput>("").unwrap();
serde_json::from_str::<Result<NoOutput, NoOutput>>("{\"Ok\": null}").unwrap();
serde_json::from_str::<Result<NoOutput, NoOutput>>("{\"Ok\": null}")
.unwrap()
.unwrap();
}

View File

@@ -841,6 +841,7 @@ async fn get_disk_info() -> Result<MetricsDisk, Error> {
}
#[tokio::test]
#[ignore]
pub async fn test_get_temp() {
println!("{}", get_temp().await.unwrap())
}
@@ -856,6 +857,7 @@ pub async fn test_get_mem_info() {
}
#[tokio::test]
#[ignore]
pub async fn test_get_disk_usage() {
println!("{:?}", get_disk_info().await.unwrap())
}

View File

@@ -1201,11 +1201,11 @@ mod fns {
#[tokio::test]
async fn test_is_subset() {
assert!(
!is_subset("/home/drbonez", "/home/drbonez/code/fakedir/../../..")
let home = std::env::var("HOME").unwrap();
let home = Path::new(&home);
assert!(!is_subset(home, &home.join("code/fakedir/../../.."))
.await
.unwrap()
)
.unwrap())
}
}