Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[chore]: fix automated tests #2506

Merged
merged 8 commits into from
Nov 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -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 changes: 10 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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)

Expand Down
3 changes: 3 additions & 0 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 7 additions & 1 deletion backend/src/bins/start_deno.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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,
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions backend/src/bins/start_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions backend/src/net/tor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down
36 changes: 32 additions & 4 deletions backend/src/procedure/js_scripts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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![] };
Expand Down
4 changes: 3 additions & 1 deletion backend/src/procedure/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
2 changes: 2 additions & 0 deletions backend/src/system.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand All @@ -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())
}
10 changes: 5 additions & 5 deletions libs/js_engine/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1201,11 +1201,11 @@ mod fns {

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

Expand Down