diff options
author | SoniEx2 <endermoneymod@gmail.com> | 2021-09-13 23:08:19 -0300 |
---|---|---|
committer | SoniEx2 <endermoneymod@gmail.com> | 2021-09-13 23:08:19 -0300 |
commit | 22e7a62e9529cc4a59941e8342f69d0f6ded60f9 (patch) | |
tree | 5f2301c2e270b452fef08ed116b0d351a07c972c /src/data/effective | |
parent | 4ba9626f711805d99c447a862682b568ad6e1e70 (diff) |
Mostly finish data source interactions
Diffstat (limited to 'src/data/effective')
-rw-r--r-- | src/data/effective/tests.rs | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/src/data/effective/tests.rs b/src/data/effective/tests.rs new file mode 100644 index 0000000..dab503f --- /dev/null +++ b/src/data/effective/tests.rs @@ -0,0 +1,108 @@ +// This file is part of GAnarchy - decentralized development hub +// Copyright (C) 2021 Soni L. +// +// 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/>. + +//! Unit tests for the effective module. + +use std::collections::BTreeSet; +use std::error; +use std::time::Duration; + +use impl_trait::impl_trait; +use url::Url; + +use crate::data::{ + DataSource, + DataSourceBase, +}; +use crate::data::kinds::{ + InstanceBaseUrl, + InstanceTitle, + ProjectFork, + RepoListUrl, +}; +use super::{EffectiveDataSource, EffectiveKind}; + +/// A helper to test [`EffectiveDataSource`] and [`EffectiveKind`]. +struct EffectiveTester; + +impl_trait! { + impl EffectiveTester { + /// Always updates successfully, with an unknown refresh interval. + impl trait DataSourceBase { + fn update(&mut self) -> ( + Option<Duration>, + Result<(), Box<dyn error::Error + Send + Sync + 'static>>, + ) { + (None, Ok(())) + } + + fn exists(&self) -> bool { + true + } + } + + /// [`InstanceTitle`] effectiveness tester. + impl trait DataSource<InstanceTitle> { + fn get_values(&self) -> Option<InstanceTitle> { + Some(String::new().into()) + } + } + + /// [`InstanceBaseUrl`] effectiveness tester. + impl trait DataSource<InstanceBaseUrl> { + fn get_values(&self) -> Option<InstanceBaseUrl> { + None + } + } + + /// [`RepoListUrl`] effectiveness tester. + impl trait DataSource<RepoListUrl> { + fn get_values(&self) -> Vec<RepoListUrl> { + // TWO for the same url + vec![ + RepoListUrl::new_for({ + Url::parse("https://example.org").unwrap() + }), + RepoListUrl::new_for({ + Url::parse("https://example.org").unwrap() + }), + ] + } + } + + /// [`ProjectFork`] effectiveness tester. + impl trait DataSource<EffectiveKind<ProjectFork>> { + fn get_values(&self) -> BTreeSet<EffectiveKind<ProjectFork>> { + vec![ + ].into_iter().collect() + } + } + + impl trait std::fmt::Display { + fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result { + write!(f, "tester") + } + } + } +} + +/// Tests that the `Option` data sources pass through. +#[test] +fn test_options() { + let eds = EffectiveDataSource(EffectiveTester); + assert_eq!(None, DataSource::<InstanceBaseUrl>::get_values(&eds)); + assert_eq!("", DataSource::<InstanceTitle>::get_values(&eds).unwrap().0); +} |