From 996d49cfa13d0e3ccd24a7d0ff0cf64e48d243f3 Mon Sep 17 00:00:00 2001 From: librelois <elois@ifee.fr> Date: Fri, 31 Jan 2020 00:45:34 +0100 Subject: [PATCH] [tests] module: create ModuleTest for tests that need a DursModule --- lib/core/module/Cargo.toml | 1 + lib/core/module/src/module_test.rs | 106 +++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 lib/core/module/src/module_test.rs diff --git a/lib/core/module/Cargo.toml b/lib/core/module/Cargo.toml index f19db073..d96717c3 100644 --- a/lib/core/module/Cargo.toml +++ b/lib/core/module/Cargo.toml @@ -24,3 +24,4 @@ serde_json = "1.0.*" structopt= "0.3.4" [features] +module-test = [] diff --git a/lib/core/module/src/module_test.rs b/lib/core/module/src/module_test.rs new file mode 100644 index 00000000..12ad14da --- /dev/null +++ b/lib/core/module/src/module_test.rs @@ -0,0 +1,106 @@ +// Copyright (C) 2017-2019 The AXIOM TEAM Association. +// +// 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/>. + +//! Define a test module for automated tests + +use crate::*; +use std::marker::PhantomData; + +/// Module test +#[derive(Debug)] +pub struct ModuleTest<DC: DursConfTrait, M: ModuleMessage> { + phantom: PhantomData<DC>, + phantom2: PhantomData<M>, +} + +/// Module test user config +#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)] +pub struct ModuleTestUserConf { + /// Field 1 + pub field1: Option<String>, + /// Field 2 + pub field2: Option<usize>, +} + +impl Merge for ModuleTestUserConf { + fn merge(self, other: Self) -> Self { + ModuleTestUserConf { + field1: self.field1.or(other.field1), + field2: self.field2.or(other.field2), + } + } +} + +/// Module test config +#[derive(Clone, Debug, Default, Deserialize, PartialEq)] +pub struct ModuleTestConf { + field1: String, + field2: usize, +} + +#[derive(StructOpt, Debug, Clone)] +#[structopt(name = "test", setting(structopt::clap::AppSettings::ColoredHelp))] +/// Gva subcommand options +pub struct ModuleTestOpt { + /// Field + #[structopt(long = "field")] + pub field: Option<String>, +} + +impl<DC: DursConfTrait, M: ModuleMessage> DursModule<DC, M> for ModuleTest<DC, M> { + type ModuleConf = ModuleTestConf; + type ModuleUserConf = ModuleTestUserConf; + type ModuleOpt = ModuleTestOpt; + + fn name() -> ModuleStaticName { + ModuleStaticName("module_test") + } + fn priority() -> ModulePriority { + ModulePriority::Recommended + } + fn ask_required_keys() -> RequiredKeys { + RequiredKeys::None + } + fn have_subcommand() -> bool { + false + } + fn generate_module_conf( + _currency_name: Option<&CurrencyName>, + _global_conf: &<DC as DursConfTrait>::GlobalConf, + _module_user_conf: Option<Self::ModuleUserConf>, + ) -> Result<(Self::ModuleConf, Option<Self::ModuleUserConf>), ModuleConfError> { + Ok(( + ModuleTestConf::default(), + Some(ModuleTestUserConf::default()), + )) + } + fn exec_subcommand( + _soft_meta_datas: &SoftwareMetaDatas<DC>, + _keys: RequiredKeysContent, + _module_conf: Self::ModuleConf, + _module_user_conf: Option<Self::ModuleUserConf>, + _subcommand_args: Self::ModuleOpt, + ) -> Option<Self::ModuleUserConf> { + unimplemented!() + } + fn start( + _soft_meta_datas: &SoftwareMetaDatas<DC>, + _keys: RequiredKeysContent, + _conf: Self::ModuleConf, + _router_sender: std::sync::mpsc::Sender<RouterThreadMessage<M>>, + ) -> Result<(), failure::Error> { + unimplemented!() + } +} -- GitLab