mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-26 02:11:53 +00:00
[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:
31
.github/workflows/test.yaml
vendored
Normal file
31
.github/workflows/test.yaml
vendored
Normal 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
|
||||||
16
Makefile
16
Makefile
@@ -15,7 +15,7 @@ EMBASSY_SRC := backend/startd.service $(BUILD_SRC)
|
|||||||
COMPAT_SRC := $(shell git ls-files system-images/compat/)
|
COMPAT_SRC := $(shell git ls-files system-images/compat/)
|
||||||
UTILS_SRC := $(shell git ls-files system-images/utils/)
|
UTILS_SRC := $(shell git ls-files system-images/utils/)
|
||||||
BINFMT_SRC := $(shell git ls-files system-images/binfmt/)
|
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_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_UI_SRC := $(shell git ls-files frontend/projects/ui)
|
||||||
FRONTEND_SETUP_WIZARD_SRC := $(shell git ls-files frontend/projects/setup-wizard)
|
FRONTEND_SETUP_WIZARD_SRC := $(shell git ls-files frontend/projects/setup-wizard)
|
||||||
@@ -48,7 +48,7 @@ endif
|
|||||||
|
|
||||||
.DELETE_ON_ERROR:
|
.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)
|
all: $(ALL_TARGETS)
|
||||||
|
|
||||||
@@ -82,6 +82,10 @@ format:
|
|||||||
cd backend && cargo +nightly fmt
|
cd backend && cargo +nightly fmt
|
||||||
cd libs && cargo +nightly fmt
|
cd libs && cargo +nightly fmt
|
||||||
|
|
||||||
|
test: $(BACKEND_SRC) $(ENVIRONMENT_FILE)
|
||||||
|
cd backend && cargo build && cargo test
|
||||||
|
cd libs && cargo test
|
||||||
|
|
||||||
sdk:
|
sdk:
|
||||||
cd backend/ && ./install-sdk.sh
|
cd backend/ && ./install-sdk.sh
|
||||||
|
|
||||||
@@ -164,20 +168,20 @@ upload-ota: results/$(BASENAME).squashfs
|
|||||||
build/lib/depends build/lib/conflicts: build/dpkg-deps/*
|
build/lib/depends build/lib/conflicts: build/dpkg-deps/*
|
||||||
build/dpkg-deps/generate.sh
|
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
|
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
|
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
|
cd system-images/binfmt && make docker-images/$(ARCH).tar && touch docker-images/$(ARCH).tar
|
||||||
|
|
||||||
snapshots: libs/snapshot_creator/Cargo.toml
|
snapshots: libs/snapshot_creator/Cargo.toml
|
||||||
cd libs/ && ./build-v8-snapshot.sh
|
cd libs/ && ./build-v8-snapshot.sh
|
||||||
cd libs/ && ./build-arm-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
|
cd backend && ARCH=$(ARCH) ./build-prod.sh
|
||||||
touch $(EMBASSY_BINS)
|
touch $(EMBASSY_BINS)
|
||||||
|
|
||||||
|
|||||||
@@ -169,6 +169,9 @@ zeroize = "1.6.0"
|
|||||||
[profile.test]
|
[profile.test]
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
|
|
||||||
|
[profile.dev]
|
||||||
|
opt-level = 3
|
||||||
|
|
||||||
[profile.dev.package.backtrace]
|
[profile.dev.package.backtrace]
|
||||||
opt-level = 3
|
opt-level = 3
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ use serde_json::Value;
|
|||||||
|
|
||||||
use crate::procedure::js_scripts::ExecuteArgs;
|
use crate::procedure::js_scripts::ExecuteArgs;
|
||||||
use crate::s9pk::manifest::PackageId;
|
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::version::{Current, VersionT};
|
||||||
use crate::Error;
|
use crate::Error;
|
||||||
|
|
||||||
@@ -23,6 +23,9 @@ fn deno_api() -> Result<(), Error> {
|
|||||||
#[command(cli_only, display(display_serializable))]
|
#[command(cli_only, display(display_serializable))]
|
||||||
async fn execute(
|
async fn execute(
|
||||||
#[arg(stdin, parse(parse_stdin_deserializable))] arg: ExecuteArgs,
|
#[arg(stdin, parse(parse_stdin_deserializable))] arg: ExecuteArgs,
|
||||||
|
#[allow(unused_variables)]
|
||||||
|
#[arg(long = "format")]
|
||||||
|
format: Option<IoFormat>,
|
||||||
) -> Result<Result<Value, (i32, String)>, Error> {
|
) -> Result<Result<Value, (i32, String)>, Error> {
|
||||||
let ExecuteArgs {
|
let ExecuteArgs {
|
||||||
procedure,
|
procedure,
|
||||||
@@ -41,6 +44,9 @@ async fn execute(
|
|||||||
#[command(cli_only, display(display_serializable))]
|
#[command(cli_only, display(display_serializable))]
|
||||||
async fn sandbox(
|
async fn sandbox(
|
||||||
#[arg(stdin, parse(parse_stdin_deserializable))] arg: ExecuteArgs,
|
#[arg(stdin, parse(parse_stdin_deserializable))] arg: ExecuteArgs,
|
||||||
|
#[allow(unused_variables)]
|
||||||
|
#[arg(long = "format")]
|
||||||
|
format: Option<IoFormat>,
|
||||||
) -> Result<Result<Value, (i32, String)>, Error> {
|
) -> Result<Result<Value, (i32, String)>, Error> {
|
||||||
let ExecuteArgs {
|
let ExecuteArgs {
|
||||||
procedure,
|
procedure,
|
||||||
|
|||||||
@@ -32,19 +32,19 @@ async fn setup_or_init(cfg_path: Option<PathBuf>) -> Result<Option<Shutdown>, Er
|
|||||||
.arg("-sf")
|
.arg("-sf")
|
||||||
.arg("/usr/lib/startos/scripts/fake-apt")
|
.arg("/usr/lib/startos/scripts/fake-apt")
|
||||||
.arg("/usr/local/bin/apt")
|
.arg("/usr/local/bin/apt")
|
||||||
.invoke(crate::ErrorKind::OpenSsh)
|
.invoke(crate::ErrorKind::Filesystem)
|
||||||
.await?;
|
.await?;
|
||||||
Command::new("ln")
|
Command::new("ln")
|
||||||
.arg("-sf")
|
.arg("-sf")
|
||||||
.arg("/usr/lib/startos/scripts/fake-apt")
|
.arg("/usr/lib/startos/scripts/fake-apt")
|
||||||
.arg("/usr/local/bin/apt-get")
|
.arg("/usr/local/bin/apt-get")
|
||||||
.invoke(crate::ErrorKind::OpenSsh)
|
.invoke(crate::ErrorKind::Filesystem)
|
||||||
.await?;
|
.await?;
|
||||||
Command::new("ln")
|
Command::new("ln")
|
||||||
.arg("-sf")
|
.arg("-sf")
|
||||||
.arg("/usr/lib/startos/scripts/fake-apt")
|
.arg("/usr/lib/startos/scripts/fake-apt")
|
||||||
.arg("/usr/local/bin/aptitude")
|
.arg("/usr/local/bin/aptitude")
|
||||||
.invoke(crate::ErrorKind::OpenSsh)
|
.invoke(crate::ErrorKind::Filesystem)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
Command::new("make-ssl-cert")
|
Command::new("make-ssl-cert")
|
||||||
|
|||||||
@@ -684,6 +684,7 @@ impl TorControl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
#[ignore]
|
||||||
async fn test() {
|
async fn test() {
|
||||||
let mut conn = torut::control::UnauthenticatedConn::new(
|
let mut conn = torut::control::UnauthenticatedConn::new(
|
||||||
TcpStream::connect(SocketAddr::from(([127, 0, 0, 1], 9051)))
|
TcpStream::connect(SocketAddr::from(([127, 0, 0, 1], 9051)))
|
||||||
|
|||||||
@@ -81,8 +81,12 @@ impl JsProcedure {
|
|||||||
_gid: ProcessGroupId,
|
_gid: ProcessGroupId,
|
||||||
_rpc_client: Option<Arc<UnixRpcClient>>,
|
_rpc_client: Option<Arc<UnixRpcClient>>,
|
||||||
) -> Result<Result<O, (i32, String)>, Error> {
|
) -> Result<Result<O, (i32, String)>, Error> {
|
||||||
Command::new("start-deno")
|
#[cfg(not(test))]
|
||||||
.arg("execute")
|
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(
|
.input(Some(&mut std::io::Cursor::new(IoFormat::Json.to_vec(
|
||||||
&ExecuteArgs {
|
&ExecuteArgs {
|
||||||
procedure: self.clone(),
|
procedure: self.clone(),
|
||||||
@@ -111,8 +115,12 @@ impl JsProcedure {
|
|||||||
timeout: Option<Duration>,
|
timeout: Option<Duration>,
|
||||||
name: ProcedureName,
|
name: ProcedureName,
|
||||||
) -> Result<Result<O, (i32, String)>, Error> {
|
) -> Result<Result<O, (i32, String)>, Error> {
|
||||||
Command::new("start-deno")
|
#[cfg(not(test))]
|
||||||
.arg("sandbox")
|
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(
|
.input(Some(&mut std::io::Cursor::new(IoFormat::Json.to_vec(
|
||||||
&ExecuteArgs {
|
&ExecuteArgs {
|
||||||
procedure: self.clone(),
|
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]
|
#[tokio::test]
|
||||||
async fn js_action_execute() {
|
async fn js_action_execute() {
|
||||||
let js_action = JsProcedure { args: vec![] };
|
let js_action = JsProcedure { args: vec![] };
|
||||||
|
|||||||
@@ -179,5 +179,7 @@ impl<'de> Deserialize<'de> for NoOutput {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_deser_no_output() {
|
fn test_deser_no_output() {
|
||||||
serde_json::from_str::<NoOutput>("").unwrap();
|
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();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -841,6 +841,7 @@ async fn get_disk_info() -> Result<MetricsDisk, Error> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
#[ignore]
|
||||||
pub async fn test_get_temp() {
|
pub async fn test_get_temp() {
|
||||||
println!("{}", get_temp().await.unwrap())
|
println!("{}", get_temp().await.unwrap())
|
||||||
}
|
}
|
||||||
@@ -856,6 +857,7 @@ pub async fn test_get_mem_info() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
#[ignore]
|
||||||
pub async fn test_get_disk_usage() {
|
pub async fn test_get_disk_usage() {
|
||||||
println!("{:?}", get_disk_info().await.unwrap())
|
println!("{:?}", get_disk_info().await.unwrap())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1201,11 +1201,11 @@ mod fns {
|
|||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
async fn test_is_subset() {
|
async fn test_is_subset() {
|
||||||
assert!(
|
let home = std::env::var("HOME").unwrap();
|
||||||
!is_subset("/home/drbonez", "/home/drbonez/code/fakedir/../../..")
|
let home = Path::new(&home);
|
||||||
|
assert!(!is_subset(home, &home.join("code/fakedir/../../.."))
|
||||||
.await
|
.await
|
||||||
.unwrap()
|
.unwrap())
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user