2021-02-02 07:26:56 +03:00
|
|
|
// Copyright (C) 2019-2021 Aleo Systems Inc.
|
2020-09-14 07:53:09 +03:00
|
|
|
// This file is part of the Leo library.
|
|
|
|
|
|
|
|
// The Leo library is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
|
|
|
|
// The Leo library 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 General Public License for more details.
|
|
|
|
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with the Leo library. If not, see <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
use crate::test_dir;
|
|
|
|
use leo_package::{
|
|
|
|
inputs::{InputFile, InputsDirectory, StateFile},
|
|
|
|
package::Package,
|
|
|
|
root::Manifest,
|
2021-04-21 13:01:11 +03:00
|
|
|
source::{MainFile, SourceDirectory},
|
2020-09-14 07:53:09 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
const TEST_PACKAGE_NAME: &str = "test-package";
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn initialize_valid_package() {
|
|
|
|
let test_directory = test_dir();
|
|
|
|
|
|
|
|
// Ensure a package can be initialized at the `test_directory`
|
2021-04-21 13:01:11 +03:00
|
|
|
assert!(Package::can_initialize(TEST_PACKAGE_NAME, &test_directory));
|
2020-09-14 07:53:09 +03:00
|
|
|
|
|
|
|
// Initialize a package at the `test_directory`
|
2021-04-21 13:01:11 +03:00
|
|
|
assert!(Package::initialize(TEST_PACKAGE_NAME, &test_directory, None).is_ok());
|
2021-04-12 16:54:37 +03:00
|
|
|
|
|
|
|
// Ensure a package is initialized at the `test_directory`
|
2021-04-21 13:01:11 +03:00
|
|
|
assert!(Package::is_initialized(TEST_PACKAGE_NAME, &test_directory));
|
2021-04-12 16:54:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn initialize_valid_package_with_author() {
|
|
|
|
let test_directory = test_dir();
|
|
|
|
|
|
|
|
// Ensure a package can be initialized at the `test_directory`
|
2021-04-21 13:01:11 +03:00
|
|
|
assert!(Package::can_initialize(TEST_PACKAGE_NAME, &test_directory));
|
2021-04-12 16:54:37 +03:00
|
|
|
|
|
|
|
// Initialize a package at the `test_directory`
|
2021-04-21 13:01:11 +03:00
|
|
|
assert!(Package::initialize(TEST_PACKAGE_NAME, &test_directory, Some(String::from("test_user"))).is_ok());
|
2020-09-14 07:53:09 +03:00
|
|
|
|
|
|
|
// Ensure a package is initialized at the `test_directory`
|
2021-04-21 13:01:11 +03:00
|
|
|
assert!(Package::is_initialized(TEST_PACKAGE_NAME, &test_directory));
|
2020-09-14 07:53:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
#[ignore]
|
|
|
|
fn initialize_fails_with_invalid_package_names() {
|
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn initialize_fails_with_existing_manifest() {
|
|
|
|
let test_directory = test_dir();
|
|
|
|
|
|
|
|
// Ensure a package can be initialized at the `test_directory`
|
2021-04-21 13:01:11 +03:00
|
|
|
assert!(Package::can_initialize(TEST_PACKAGE_NAME, &test_directory));
|
2020-09-14 07:53:09 +03:00
|
|
|
|
|
|
|
// Manually add a manifest file to the `test_directory`
|
2021-04-12 16:54:37 +03:00
|
|
|
Manifest::new(TEST_PACKAGE_NAME, None)
|
2021-02-25 06:25:41 +03:00
|
|
|
.unwrap()
|
|
|
|
.write_to(&test_directory)
|
|
|
|
.unwrap();
|
2020-09-14 07:53:09 +03:00
|
|
|
|
|
|
|
// Attempt to initialize a package at the `test_directory`
|
2021-04-21 13:01:11 +03:00
|
|
|
assert!(Package::initialize(TEST_PACKAGE_NAME, &test_directory, None).is_err());
|
2020-09-14 07:53:09 +03:00
|
|
|
|
|
|
|
// Ensure package is not initialized at the `test_directory`
|
2021-04-21 13:01:11 +03:00
|
|
|
assert!(!Package::is_initialized(TEST_PACKAGE_NAME, &test_directory));
|
2020-09-14 07:53:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn initialize_fails_with_existing_input_file() {
|
|
|
|
let test_directory = test_dir();
|
|
|
|
|
|
|
|
// Ensure a package can be initialized at the `test_directory`
|
2021-04-21 13:01:11 +03:00
|
|
|
assert!(Package::can_initialize(TEST_PACKAGE_NAME, &test_directory));
|
2020-09-14 07:53:09 +03:00
|
|
|
|
|
|
|
// Manually add an inputs directory and an input file to the `test_directory`
|
|
|
|
InputsDirectory::create(&test_directory).unwrap();
|
|
|
|
InputFile::new(TEST_PACKAGE_NAME).write_to(&test_directory).unwrap();
|
|
|
|
|
|
|
|
// Attempt to initialize a package at the `test_directory`
|
2021-04-21 13:01:11 +03:00
|
|
|
assert!(Package::initialize(TEST_PACKAGE_NAME, &test_directory, Some(String::from("test_user"))).is_err());
|
2020-09-14 07:53:09 +03:00
|
|
|
|
|
|
|
// Ensure package is not initialized at the `test_directory`
|
2021-04-21 13:01:11 +03:00
|
|
|
assert!(!Package::is_initialized(TEST_PACKAGE_NAME, &test_directory));
|
2020-09-14 07:53:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn initialize_fails_with_existing_state_file() {
|
|
|
|
let test_directory = test_dir();
|
|
|
|
|
|
|
|
// Ensure a package can be initialized at the `test_directory`
|
2021-04-21 13:01:11 +03:00
|
|
|
assert!(Package::can_initialize(TEST_PACKAGE_NAME, &test_directory));
|
2020-09-14 07:53:09 +03:00
|
|
|
|
|
|
|
// Manually add an inputs directory and a state file to the `test_directory`
|
|
|
|
InputsDirectory::create(&test_directory).unwrap();
|
|
|
|
StateFile::new(TEST_PACKAGE_NAME).write_to(&test_directory).unwrap();
|
|
|
|
|
|
|
|
// Attempt to initialize a package at the `test_directory`
|
2021-04-21 13:01:11 +03:00
|
|
|
assert!(Package::initialize(TEST_PACKAGE_NAME, &test_directory, None).is_err());
|
2020-09-14 07:53:09 +03:00
|
|
|
|
|
|
|
// Ensure package is not initialized at the `test_directory`
|
2021-04-21 13:01:11 +03:00
|
|
|
assert!(!Package::is_initialized(TEST_PACKAGE_NAME, &test_directory));
|
2020-09-14 07:53:09 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn initialize_fails_with_existing_main_file() {
|
|
|
|
let test_directory = test_dir();
|
|
|
|
|
|
|
|
// Ensure a package can be initialized at the `test_directory`
|
2021-04-21 13:01:11 +03:00
|
|
|
assert!(Package::can_initialize(TEST_PACKAGE_NAME, &test_directory));
|
2020-09-14 07:53:09 +03:00
|
|
|
|
|
|
|
// Manually add a source directory and a main file to the `test_directory`
|
|
|
|
SourceDirectory::create(&test_directory).unwrap();
|
|
|
|
MainFile::new(TEST_PACKAGE_NAME).write_to(&test_directory).unwrap();
|
|
|
|
|
|
|
|
// Attempt to initialize a package at the `test_directory`
|
2021-04-21 13:01:11 +03:00
|
|
|
assert!(Package::initialize(TEST_PACKAGE_NAME, &test_directory, None).is_err());
|
2020-09-14 07:53:09 +03:00
|
|
|
|
|
|
|
// Ensure package is not initialized at the `test_directory`
|
2021-04-21 13:01:11 +03:00
|
|
|
assert!(!Package::is_initialized(TEST_PACKAGE_NAME, &test_directory));
|
2020-09-14 07:53:09 +03:00
|
|
|
}
|