From 22e7a62e9529cc4a59941e8342f69d0f6ded60f9 Mon Sep 17 00:00:00 2001 From: SoniEx2 Date: Mon, 13 Sep 2021 23:08:19 -0300 Subject: Mostly finish data source interactions --- src/data/effective/tests.rs | 108 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 src/data/effective/tests.rs (limited to 'src/data/effective') 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 . + +//! 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, + Result<(), Box>, + ) { + (None, Ok(())) + } + + fn exists(&self) -> bool { + true + } + } + + /// [`InstanceTitle`] effectiveness tester. + impl trait DataSource { + fn get_values(&self) -> Option { + Some(String::new().into()) + } + } + + /// [`InstanceBaseUrl`] effectiveness tester. + impl trait DataSource { + fn get_values(&self) -> Option { + None + } + } + + /// [`RepoListUrl`] effectiveness tester. + impl trait DataSource { + fn get_values(&self) -> Vec { + // 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> { + fn get_values(&self) -> BTreeSet> { + 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::::get_values(&eds)); + assert_eq!("", DataSource::::get_values(&eds).unwrap().0); +} -- cgit 1.4.1