-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #238 from canonical/integration-tests
Setup environment for running integration tests
- Loading branch information
Showing
11 changed files
with
224 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Run integration tests | ||
on: | ||
push: | ||
branches: [ main ] | ||
paths: | ||
- server/** | ||
- client/** | ||
- tests/** | ||
- ".github/workflows/run_integration_tests.yaml" | ||
pull_request: | ||
branches: [ main ] | ||
paths: | ||
- server/** | ||
- client/** | ||
- tests/** | ||
- ".github/workflows/run_integration_tests.yaml" | ||
concurrency: | ||
group: ${{ github.workflow }}-${{ github.ref }} | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
test: | ||
runs-on: [self-hosted, linux, large, jammy, x64] | ||
defaults: | ||
run: | ||
working-directory: tests | ||
steps: | ||
- uses: actions/checkout@v4 | ||
- name: Set up docker buildx | ||
uses: docker/setup-buildx-action@v3 | ||
with: | ||
config-inline: | | ||
[registry."docker.io"] | ||
mirrors = ["https://github-runner-dockerhub-cache.canonical.com:5000"] | ||
- name: Install docker compose | ||
run: | | ||
sudo apt update | ||
sudo apt install -y docker-compose-v2 | ||
- name: Build and run integration tests | ||
run: | | ||
docker compose up --build --abort-on-container-exit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
[package] | ||
name = "integration-tests" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
hwlib = { path = "client/hwlib" } | ||
tokio = { version = "1.0", features = ["full", "test-util"] } | ||
anyhow = "1.0" | ||
simple_test_case = "1.2.0" | ||
|
||
[[test]] | ||
name = "integration" | ||
path = "src/integration_test.rs" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FROM ubuntu:24.04 | ||
|
||
# Install Rust and required packages | ||
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \ | ||
curl \ | ||
build-essential \ | ||
pkgconf \ | ||
libssl-dev \ | ||
lsb-release \ | ||
kmod \ | ||
python3 \ | ||
python3-pip \ | ||
rustup | ||
|
||
RUN rustup default stable | ||
|
||
WORKDIR /app | ||
|
||
COPY Cargo.toml . | ||
COPY src src/ | ||
|
||
CMD ["cargo", "test", "--test", "integration", "--", "--nocapture"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# Integration tests for the project | ||
|
||
This folder contains the tests for the hardware-api project that check | ||
how client and server communicate. | ||
|
||
To run them, first install | ||
[docker](https://docs.docker.com/engine/install/ubuntu/) and [setup | ||
permissions](https://docs.docker.com/engine/install/linux-postinstall/). | ||
|
||
Then, run the tests with `docker compose`: | ||
|
||
```sh | ||
docker compose up --build --abort-on-container-exit | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
services: | ||
hwapi-server-integration: | ||
build: | ||
context: ../server | ||
dockerfile: Dockerfile | ||
args: | ||
IMPORT_TOOL_PATH: "" | ||
C3_URL: https://c3_url | ||
DB_URL: sqlite:////home/server/test-integration.db | ||
ports: | ||
- "8080:8080" | ||
|
||
integration-tests: | ||
build: | ||
context: . | ||
dockerfile: Dockerfile | ||
depends_on: | ||
- hwapi-server-integration | ||
volumes: | ||
- ../client:/app/client | ||
environment: | ||
- API_URL=http://hwapi-server-integration:8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* Copyright 2024 Canonical Ltd. | ||
* All rights reserved. | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
* Written by: | ||
* Nadzeya Hutsko <[email protected]> | ||
*/ | ||
|
||
use anyhow::Result; | ||
use std::path::PathBuf; | ||
use simple_test_case::test_case; | ||
use hwlib::{ | ||
models::request_validators::{CertificationStatusRequest, Paths}, | ||
models::response_validators::CertificationStatusResponse, | ||
send_certification_status_request, | ||
}; | ||
|
||
fn get_test_device_paths(device_type: &str) -> Paths { | ||
let base_path = PathBuf::from("/app/client/hwlib/test_data/amd64").join(device_type); | ||
Paths { | ||
smbios_entry_filepath: base_path.join("smbios_entry_point"), | ||
smbios_table_filepath: base_path.join("DMI"), | ||
cpuinfo_filepath: PathBuf::from("./none"), | ||
max_cpu_frequency_filepath: base_path.join("cpuinfo_max_freq"), | ||
device_tree_dirpath: PathBuf::from("./none"), | ||
proc_version_filepath: base_path.join("version"), | ||
} | ||
} | ||
|
||
#[test_case( | ||
"dgx_station"; | ||
"dgx_station" // test name | ||
)] | ||
#[test_case( | ||
"dell_xps13"; | ||
"dell_xps13" | ||
)] | ||
#[test_case( | ||
"thinkstation_p620"; | ||
"thinkstation_p620" | ||
)] | ||
#[tokio::test] | ||
async fn test_certification_request(dir_path: &str) -> Result<()> { | ||
let api_url = match std::env::var("API_URL") { | ||
Ok(url) => url, | ||
Err(..) => panic!("API_URL environment variable must be specified"), | ||
}; | ||
let cert_request = CertificationStatusRequest::new(get_test_device_paths(dir_path))?; | ||
let response = send_certification_status_request(api_url, &cert_request).await?; | ||
|
||
// Currently all the responses should match the "Not Seen" status, it'll be updated | ||
// once snapshot tests are defined | ||
match response { | ||
CertificationStatusResponse::NotSeen => { | ||
// Here, we don't need any further assertions. | ||
// We simply want to ensure this case is hit. | ||
}, | ||
_ => { | ||
panic!("Expected response to be NotSeen, but it was {:?}", response); | ||
}, | ||
} | ||
|
||
Ok(()) | ||
} | ||
|
||
|
||
#[tokio::test] | ||
async fn test_server_connection_error() -> Result<()> { | ||
let result = send_certification_status_request( | ||
"http://non-existent-server:8080".to_string(), | ||
&CertificationStatusRequest::new(get_test_device_paths("dell_xps13"))?, | ||
).await; | ||
|
||
assert!(result.is_err()); | ||
Ok(()) | ||
} |