Skip to content

Commit

Permalink
Merge pull request #2664 from lann/factors-tests
Browse files Browse the repository at this point in the history
factors: Add basic CI
  • Loading branch information
lann authored Jul 19, 2024
2 parents 2565311 + 4ec282b commit 7c6faed
Show file tree
Hide file tree
Showing 14 changed files with 68 additions and 21 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/factors.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# TODO(factors): remove after factors branch passes regular CI
name: Factors
on:
push:
branches: ["factors"]
pull_request:
branches: ["factors"]
jobs:
factors-tests:
runs-on: ubuntu-22.04-4core-spin
steps:
- uses: actions/checkout@v3
- name: setup dependencies
uses: ./.github/actions/spin-ci-dependencies
with:
rust: true
rust-wasm: true
rust-cache: true
- name: Run factors tests
run: ./run-factors-tests.sh
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion crates/factor-variables/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main() {
println!("cargo::rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=build.rs");
// Enable spin-factors-derive to emit expanded macro output.
let out_dir = std::env::var("OUT_DIR").unwrap();
println!("cargo:rustc-env=SPIN_FACTORS_DERIVE_EXPAND_DIR={out_dir}");
Expand Down
2 changes: 1 addition & 1 deletion crates/factor-wasi/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fn main() {
println!("cargo::rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=build.rs");
// Enable spin-factors-derive to emit expanded macro output.
let out_dir = std::env::var("OUT_DIR").unwrap();
println!("cargo:rustc-env=SPIN_FACTORS_DERIVE_EXPAND_DIR={out_dir}");
Expand Down
1 change: 0 additions & 1 deletion crates/factor-wasi/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ impl<'a> MountFilesContext<'a> {
guest_path: impl AsRef<str>,
writable: bool,
) -> anyhow::Result<()> {
use wasmtime_wasi::{DirPerms, FilePerms};
let (dir_perms, file_perms) = if writable {
(DirPerms::all(), FilePerms::all())
} else {
Expand Down
3 changes: 3 additions & 0 deletions crates/factors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ tokio = { version = "1", features = ["macros", "rt", "sync"] }
toml = "0.8"
wasmtime-wasi-http = { workspace = true }

[build-dependencies]
cargo-target-dep = { git = "https://github.com/fermyon/cargo-target-dep", rev = "482f269eceb7b1a7e8fc618bf8c082dd24979cf1" }

[lints]
workspace = true
19 changes: 19 additions & 0 deletions crates/factors/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use std::path::Path;

use cargo_target_dep::build_target_dep;

fn main() {
println!("cargo:rerun-if-changed=build.rs");
// Enable spin-factors-derive to emit expanded macro output.
let out_dir = std::env::var("OUT_DIR").unwrap();
println!("cargo:rustc-env=SPIN_FACTORS_DERIVE_EXPAND_DIR={out_dir}");

let root = "tests/smoke-app";
build_target_dep(root, Path::new("tests/smoke-app/smoke_app.wasm"))
.release()
.target("wasm32-wasi")
.build();
println!("cargo:rerun-if-changed={root}/Cargo.toml");
println!("cargo:rerun-if-changed={root}/Cargo.lock");
println!("cargo:rerun-if-changed={root}/src");
}
1 change: 1 addition & 0 deletions crates/factors/tests/smoke-app/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
target/
.spin/
*.wasm
8 changes: 2 additions & 6 deletions crates/factors/tests/smoke-app/spin.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,7 @@ route = "/..."
component = "smoke-app"

[component.smoke-app]
source = "target/wasm32-wasi/release/smoke_app.wasm"
source = "smoke_app.wasm"
allowed_outbound_hosts = ["https://{{ host }}"]
key_value_stores = ["default"]
variables = { "other" = "<{{ other }}>"}

[component.smoke-app.build]
command = "cargo build --target wasm32-wasi --release"
watch = ["src/**/*.rs", "Cargo.toml"]
variables = { "other" = "<{{ other }}>"}
2 changes: 1 addition & 1 deletion crates/factors/tests/smoke.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ async fn smoke_test_works() -> anyhow::Result<()> {
None,
)
.await?;
let app = App::inert(locked);
let app = App::new("test-app", locked);

let engine = wasmtime::Engine::new(wasmtime::Config::new().async_support(true))?;
let mut linker = wasmtime::component::Linker::new(&engine);
Expand Down
4 changes: 2 additions & 2 deletions crates/key-value/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use spin_world::v2::key_value;
use std::{collections::HashSet, sync::Arc};
use table::Table;

mod host_component;
// TODO(factors): Code left for reference; remove after migration to factors
// mod host_component;
mod util;

pub use host_component::{manager, KeyValueComponent};
pub use util::{
CachingStoreManager, DefaultManagerGetter, DelegatingStoreManager, EmptyStoreManager,
};
Expand Down
14 changes: 9 additions & 5 deletions crates/key-value/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,15 @@ impl DelegatingStoreManager {
#[async_trait]
impl StoreManager for DelegatingStoreManager {
async fn get(&self, name: &str) -> Result<Arc<dyn Store>, Error> {
let store = match self.delegates.get(name) {
Some(store) => store,
None => &(self.default_manager)(name).ok_or(Error::NoSuchStore)?,
};
store.get(name).await
match self.delegates.get(name) {
Some(store) => store.get(name).await,
None => {
(self.default_manager)(name)
.ok_or(Error::NoSuchStore)?
.get(name)
.await
}
}
}

fn is_defined(&self, store_name: &str) -> bool {
Expand Down
8 changes: 4 additions & 4 deletions crates/sqlite/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
mod host_component;
// TODO(factors): Code left for reference; remove after migration to factors
// mod host_component;

use spin_app::{async_trait, MetadataKey};
use spin_app::MetadataKey;
use spin_core::wasmtime::component::Resource;
use spin_world::async_trait;
use spin_world::v1::sqlite::Error as V1SqliteError;
use spin_world::v2::sqlite;
use std::{collections::HashSet, sync::Arc};

pub use host_component::SqliteComponent;

pub const DATABASES_KEY: MetadataKey<HashSet<String>> = MetadataKey::new("databases");

/// A store of connections for all accessible databases for an application
Expand Down
4 changes: 4 additions & 0 deletions run-factors-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
# TODO(factors): Remove after enabling CI for factors branch

cargo test -p '*factor*'

0 comments on commit 7c6faed

Please sign in to comment.