Skip to content
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
10 changes: 9 additions & 1 deletion score/kvs/kvs_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#include "score/os/stat.h"
#include "score/utility.hpp"

#include <unistd.h>

TEST(kvs_constructor, move_constructor)
{
const std::uint32_t instance_b = 5;
Expand Down Expand Up @@ -1919,6 +1921,12 @@ TEST(kvs_flush, flush_failure_mutex)

TEST(kvs_flush, flush_failure_rotate_snapshots)
{
// Root ignores file permissions, so flush would succeed.
if (geteuid() == 0)
{
GTEST_SKIP() << "File permissions are not enforced for root.";
}

prepare_environment();
// Test folder for permission handling.
std::string permissions_dir = data_dir + "permissions/";
Expand All @@ -1936,7 +1944,7 @@ TEST(kvs_flush, flush_failure_rotate_snapshots)
permissions_dir, std::filesystem::perms::owner_read, std::filesystem::perm_options::replace);
auto flush_result = result.value().flush();

EXPECT_FALSE(flush_result);
ASSERT_FALSE(flush_result);
EXPECT_EQ(static_cast<ErrorCode>(*flush_result.error()), ErrorCode::PhysicalStorageFailure);

cleanup_environment();
Expand Down
6 changes: 3 additions & 3 deletions score/kvs/rust_kvs/json_backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -999,9 +999,9 @@ mod error_code_tests {

#[cfg(test)]
mod json_backend_builder_tests {
use crate::test_utils::tempdir;
use crate::{json_backend::JsonBackendBuilder, prelude::KvsBackend};
use std::path::PathBuf;
use tempfile::tempdir;

#[test]
fn test_new_ok() {
Expand Down Expand Up @@ -1086,9 +1086,9 @@ mod json_backend_tests {
use crate::json_backend::{JsonBackend, JsonBackendBuilder};
use crate::kvs_api::{InstanceId, SnapshotId, KVS_MAX_KEY_LENGTH_BYTES};
use crate::kvs_value::{KvsMap, KvsValue};
use crate::test_utils::tempdir;
use std::os::unix::fs::PermissionsExt;
use std::path::{Path, PathBuf};
use tempfile::tempdir;

/// Expected permissions of KVS JSON and hash files: 0640.
const EXPECTED_FILE_MODE: u32 = 0o640;
Expand Down Expand Up @@ -1525,10 +1525,10 @@ mod kvs_backend_tests {
use crate::kvs_api::{InstanceId, SnapshotId};
use crate::kvs_backend::KvsBackend;
use crate::kvs_value::{KvsMap, KvsValue};
use crate::test_utils::tempdir;
use std::fs;
use std::os::unix::fs::PermissionsExt;
use std::path::Path;
use tempfile::tempdir;

/// Expected permissions of KVS JSON and hash files: 0640.
const EXPECTED_FILE_MODE: u32 = 0o640;
Expand Down
2 changes: 1 addition & 1 deletion score/kvs/rust_kvs/kvs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,8 +334,8 @@ mod kvs_tests {
use crate::kvs_builder::KvsData;
use crate::kvs_value::{KvsMap, KvsValue};
use crate::log::ScoreDebug;
use crate::test_utils::tempdir;
use std::sync::{Arc, Mutex};
use tempfile::tempdir;

/// Most tests can be performed with mocked backend.
/// Only those with file handling must use concrete implementation.
Expand Down
2 changes: 1 addition & 1 deletion score/kvs/rust_kvs/kvs_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,10 @@ mod kvs_builder_tests {
use crate::kvs_api::{InstanceId, KvsApi, KvsDefaults, KvsLoad, SnapshotId};
use crate::kvs_builder::{KvsBuilder, KVS_MAX_INSTANCES, KVS_POOL};
use crate::kvs_value::{KvsMap, KvsValue};
use crate::test_utils::tempdir;
use core::ops::DerefMut;
use std::path::{Path, PathBuf};
use std::sync::{LazyLock, Mutex, MutexGuard};
use tempfile::tempdir;

/// Serial test execution mutex.
static SERIAL_TEST: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(()));
Expand Down
2 changes: 2 additions & 0 deletions score/kvs/rust_kvs/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ pub mod kvs_mock;
pub mod kvs_serialize;
pub mod kvs_value;
mod log;
#[cfg(test)]
mod test_utils;

/// Prelude module for convenient imports
pub mod prelude {
Expand Down
25 changes: 25 additions & 0 deletions score/kvs/rust_kvs/test_utils.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// *******************************************************************************
// Copyright (c) 2026 Contributors to the Eclipse Foundation
//
// See the NOTICE file(s) distributed with this work for additional
// information regarding copyright ownership.
//
// This program and the accompanying materials are made available under the
// terms of the Apache License Version 2.0 which is available at
// <https://www.apache.org/licenses/LICENSE-2.0>
//
// SPDX-License-Identifier: Apache-2.0
// *******************************************************************************

//! Helpers shared by unit tests.

/// Create a temporary directory for a test.
/// On QNX, `/tmp` can't hold directories.
/// The test's working directory can, so the directory is created there.
pub fn tempdir() -> std::io::Result<tempfile::TempDir> {
if cfg!(target_os = "nto") {
tempfile::tempdir_in(".")
} else {
tempfile::tempdir()
}
}
Loading