Browse Source

Create API endpoints

master
NGnius 4 years ago
parent
commit
610ba3b0b3
2 changed files with 125 additions and 5 deletions
  1. +58
    -5
      src/lib.rs
  2. +67
    -0
      src/tests.rs

+ 58
- 5
src/lib.rs View File

@@ -1,7 +1,60 @@
use std::vec::Vec;

#[cfg(test)]
mod tests {
#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}
mod tests;

// public-facing library functions

pub fn init(conf_dir: &str) -> bool {
// TODO
return conf_dir != "" && false;
}

pub fn install(pkg_name: &str) -> bool {
// TODO
return pkg_name != "" && false;
}

pub fn update_all() -> bool {
// TODO
return false;
}

pub fn update(pkg_name: &str) -> bool {
// TODO
return pkg_name != "" && false;
}

pub fn resolve_dependencies(pkg_name: &str) -> Vec<String> {
// TODO
let mut result = Vec::<String>::new();
result.push(pkg_name.to_string());
return result;
}

pub fn remove(pkg_name: &str) -> bool {
// TODO
return pkg_name != "" && false;
}

pub fn list_packages() -> Vec<String> {
// TODO
return Vec::<String>::new();
}

// remote package providers

pub fn add_server(server_name: &str) -> bool {
// TODO
return server_name != "" && false;
}

pub fn remove_server(server_name: &str) -> bool {
// TODO
return server_name != "" && false;
}

pub fn list_servers() -> Vec<String> {
// TODO
return Vec::<String>::new();
}

+ 67
- 0
src/tests.rs View File

@@ -0,0 +1,67 @@
use super::*;

const CONFIG_DIR: &str = "./test";

#[test]
fn it_works() {
assert_eq!(2 + 2, 4);
}

#[test]
fn lib_test_init() {
assert_eq!(init(CONFIG_DIR), true);
}

#[test]
fn pkg_test_install() {
assert_eq!(init(CONFIG_DIR), true);
assert_eq!(install("test"), true);
}

#[test]
fn pkg_test_update_all() {
assert_eq!(init(CONFIG_DIR), true);
assert_eq!(update_all(), true);
}

#[test]
fn pkg_test_update() {
assert_eq!(init(CONFIG_DIR), true);
assert_eq!(update("test"), true);
}

#[test]
fn pkg_test_resolve_dependencies() {
assert_eq!(init(CONFIG_DIR), true);
assert_ne!(resolve_dependencies("test").len(), 0);
}

#[test]
fn pkg_test_remove() {
assert_eq!(init(CONFIG_DIR), true);
assert_eq!(remove("test"), true);
}

#[test]
fn pkg_test_list() {
assert_eq!(init(CONFIG_DIR), true);
assert_ne!(list_packages().len(), 0);
}

#[test]
fn server_test_add() {
assert_eq!(init(CONFIG_DIR), true);
assert_eq!(add_server("http://test.org"), true);
}

#[test]
fn server_test_remove() {
assert_eq!(init(CONFIG_DIR), true);
assert_eq!(remove_server("http://test.org"), true);
}

#[test]
fn server_test_list() {
assert_eq!(init(CONFIG_DIR), true);
assert_ne!(list_servers().len(), 0);
}