Add file name tests for harness

next
Sayan Nandan 3 years ago
parent 90ef10a56d
commit b005ca57c5
No known key found for this signature in database
GPG Key ID: 8BC07A0A4D41DD52

@ -59,7 +59,7 @@ impl ToString for BuildMode {
/// Returns the paths of the files for the given target folder
pub fn get_files_index(target_folder: &PathBuf) -> Vec<PathBuf> {
let mut paths = Vec::with_capacity(3);
let mut paths = Vec::with_capacity(BINARIES.len());
for binary in BINARIES {
paths.push(util::concat_path(binary, target_folder));
}

@ -37,7 +37,7 @@ use std::path::PathBuf;
use zip::{write::FileOptions, ZipWriter};
/// Returns the bundle name
fn get_bundle_name() -> String {
pub fn get_bundle_name() -> String {
let mut filename = format!("sky-bundle-v{VERSION}");
match util::get_var(util::VAR_ARTIFACT) {
Some(artifact) => {

@ -44,7 +44,7 @@ impl LinuxPackageType {
}
}
/// Returns the file name for the package
fn get_file_name(&self) -> String {
pub fn get_file_name(&self) -> String {
let mut filename = format!("skytable-v{VERSION}");
match util::get_var(util::VAR_ARTIFACT) {
Some(artifact) => {

@ -35,6 +35,8 @@ mod error;
mod linuxpkg;
mod presetup;
mod test;
#[cfg(test)]
mod tests;
use crate::{
cli::HarnessWhat,
error::{HarnessError, HarnessResult},

@ -24,7 +24,11 @@
*
*/
use crate::{build::BuildMode, util, HarnessError, HarnessResult};
use crate::{
build::BuildMode,
util::{self, SLEEP_FOR_STARTUP, SLEEP_FOR_TERMINATION},
HarnessError, HarnessResult,
};
use openssl::{
asn1::Asn1Time,
bn::{BigNum, MsbOption},
@ -73,18 +77,19 @@ pub fn get_run_server_cmd(server_id: &'static str, target_folder: impl AsRef<Pat
pub fn start_servers(s1_cmd: Command, s2_cmd: Command) -> HarnessResult<(Child, Child)> {
info!("Starting server1 ...");
let s1 = util::get_child("start server1", s1_cmd)?;
util::sleep_sec(10);
util::sleep_sec(SLEEP_FOR_STARTUP);
info!("Starting server2 ...");
let s2 = util::get_child("start server2", s2_cmd)?;
util::sleep_sec(10);
util::sleep_sec(SLEEP_FOR_STARTUP);
Ok((s1, s2))
}
/// Kill the servers (run the command and then sleep for 10s)
fn kill_servers() -> HarnessResult<()> {
info!("Terminating server instances ...");
kill_servers_inner()?;
// sleep
util::sleep_sec(20);
util::sleep_sec(SLEEP_FOR_TERMINATION);
Ok(())
}
@ -114,6 +119,7 @@ pub fn run_test() -> HarnessResult<()> {
}
// clean up
info!("Cleaning up test directories ...");
fs::remove_dir_all("server1").map_err(|e| {
HarnessError::Other(format!("Failed to remove dir `server1` with error: {e}"))
})?;

@ -0,0 +1,108 @@
/*
* Created on Mon Mar 21 2022
*
* This file is a part of Skytable
* Skytable (formerly known as TerrabaseDB or Skybase) is a free and open-source
* NoSQL database written by Sayan Nandan ("the Author") with the
* vision to provide flexibility in data modelling without compromising
* on performance, queryability or scalability.
*
* Copyright (c) 2022, Sayan Nandan <ohsayan@outlook.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
*/
use crate::util::WORKSPACE_ROOT;
use crate::{
build::{self, BuildMode},
bundle, linuxpkg, util,
};
use libsky::VERSION;
use std::env;
use std::path::PathBuf;
#[test]
fn file_names() {
const ARTIFACT: &str = "x86_64-linux-gnu";
const TARGET: &str = "x86_64-unknown-linux-gnu";
// without a target
// check bundle name
let bundle_name = bundle::get_bundle_name();
assert_eq!(bundle_name, format!("sky-bundle-v{VERSION}.zip"));
// check target folder
let target_folder_debug = util::get_target_folder(BuildMode::Debug);
assert_eq!(
target_folder_debug.to_string_lossy(),
format!("{WORKSPACE_ROOT}target/debug")
);
let target_folder_release = util::get_target_folder(BuildMode::Release);
assert_eq!(
target_folder_release.to_string_lossy(),
format!("{WORKSPACE_ROOT}target/release")
);
// check files index
// files index for debug
let files_index = build::get_files_index(&target_folder_debug);
let expected_files_index: Vec<PathBuf> = build::BINARIES
.iter()
.map(|bin| format!("{WORKSPACE_ROOT}target/debug/{bin}").into())
.collect();
assert_eq!(files_index, expected_files_index);
// files index for release
let files_index = build::get_files_index(&target_folder_release);
let expected_files_index: Vec<PathBuf> = build::BINARIES
.iter()
.map(|bin| format!("{WORKSPACE_ROOT}target/release/{bin}").into())
.collect();
assert_eq!(files_index, expected_files_index);
// linux package name
let name = linuxpkg::LinuxPackageType::Deb.get_file_name();
assert_eq!(name, format!("skytable-v{VERSION}.deb"));
// with a target
env::set_var(util::VAR_ARTIFACT, ARTIFACT); // check bundle name
env::set_var(util::VAR_TARGET, TARGET);
let bundle_name = bundle::get_bundle_name();
assert_eq!(bundle_name, format!("sky-bundle-v{VERSION}-{ARTIFACT}.zip"));
// check target folder
let target_folder_debug = util::get_target_folder(BuildMode::Debug);
assert_eq!(
target_folder_debug.to_string_lossy(),
format!("{WORKSPACE_ROOT}target/{TARGET}/debug")
);
let target_folder_release = util::get_target_folder(BuildMode::Release);
assert_eq!(
target_folder_release.to_string_lossy(),
format!("{WORKSPACE_ROOT}target/{TARGET}/release")
);
// check files index
// files index for debug
let files_index = build::get_files_index(&target_folder_debug);
let expected_files_index: Vec<PathBuf> = build::BINARIES
.iter()
.map(|bin| format!("{WORKSPACE_ROOT}target/{TARGET}/debug/{bin}").into())
.collect();
assert_eq!(files_index, expected_files_index);
// files index for release
let files_index = build::get_files_index(&target_folder_release);
let expected_files_index: Vec<PathBuf> = build::BINARIES
.iter()
.map(|bin| format!("{WORKSPACE_ROOT}target/{TARGET}/release/{bin}").into())
.collect();
assert_eq!(files_index, expected_files_index);
// linux package name
let name = linuxpkg::LinuxPackageType::Deb.get_file_name();
assert_eq!(name, format!("skytable-v{VERSION}-{ARTIFACT}.deb"));
}

@ -34,9 +34,17 @@ use std::process::Child;
use std::process::Command;
pub type ExitCode = Option<i32>;
#[cfg(not(test))]
pub const VAR_TARGET: &str = "TARGET";
#[cfg(test)]
pub const VAR_TARGET: &str = "TARGET_TESTSUITE";
#[cfg(not(test))]
pub const VAR_ARTIFACT: &str = "ARTIFACT";
#[cfg(test)]
pub const VAR_ARTIFACT: &str = "ARTIFACT_TESTSUITE";
pub const WORKSPACE_ROOT: &str = env!("ROOT_DIR");
pub const SLEEP_FOR_STARTUP: u64 = 15;
pub const SLEEP_FOR_TERMINATION: u64 = 20;
pub fn get_var(var: &str) -> Option<String> {
env::var_os(var).map(|v| v.to_string_lossy().to_string())
@ -77,8 +85,8 @@ pub fn sleep_sec(secs: u64) {
pub fn get_target_folder(mode: BuildMode) -> PathBuf {
match env::var_os(VAR_TARGET).map(|v| v.to_string_lossy().to_string()) {
Some(target) => format!("{WORKSPACE_ROOT}/target/{target}/{}", mode.to_string()).into(),
None => format!("{WORKSPACE_ROOT}/target/{}", mode.to_string()).into(),
Some(target) => format!("{WORKSPACE_ROOT}target/{target}/{}", mode.to_string()).into(),
None => format!("{WORKSPACE_ROOT}target/{}", mode.to_string()).into(),
}
}

Loading…
Cancel
Save