diff --git a/lib/core/module/Cargo.toml b/lib/core/module/Cargo.toml index f19db0733ff422cf5a3693198fe30315aeea8547..d96717c351f364f703b17f5e302d777037cb8bae 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 0000000000000000000000000000000000000000..12ad14da05f1385c0f62013b085fc4ce12888563 --- /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!() + } +}