Browse Source

0.1.9

master 0.1.9
Ryan 1 year ago
parent
commit
eef73a0577
  1. 2
      Cargo.toml
  2. 3
      README.md
  3. 6
      RELEASE_NOTE.md
  4. 3
      src/lib.rs
  5. 84
      src/string.rs

2
Cargo.toml

@ -1,6 +1,6 @@
[package]
name = "device-common"
version = "0.1.6"
version = "0.1.9"
edition = "2021"
authors = ["Ryan Bae <jh.bae@anypointmedia.com>"]

3
README.md

@ -8,6 +8,7 @@ device-service 에서 공통으로 쓰이는 기능들의 집합
- log.rs : log 관련 기능 / static function 으로 사용 가능한 expect_or_log
- metrics.rs : cpu / memory 등 기본 metric 수집 기능
- orchestration.rs : orchestration 정보를 로드하는 기능
- string.rs : string 확장 기능
- aws/kinesis.rs : AWS Kinesis Stream 관련 기능
- aws/parameter_store.rs : AWS Parameter Store 관련 기능
- aws/s3.rs : AWS S3 관련 기능
- aws/s3.rs : AWS S3 관련 기능]

6
RELEASE_NOTE.md

@ -36,4 +36,8 @@ first deploy
0.1.8
======
- added campaign database information
- added campaign database information
0.1.9
======
- added string.rs

3
src/lib.rs

@ -7,4 +7,5 @@ pub mod env;
pub mod orchestration;
pub mod metrics;
pub mod constants;
pub mod aws;
pub mod aws;
pub mod string;

84
src/string.rs

@ -0,0 +1,84 @@
use std::path::{Path, PathBuf};
pub fn remove_extension(file_path: &str) -> String {
let path = Path::new(file_path);
match path.file_stem() {
Some(stem) => {
let mut new_path = PathBuf::from(stem);
if let Some(parent) = path.parent() {
new_path = parent.join(stem);
}
new_path.to_string_lossy().into_owned()
}
None => file_path.to_string()
}
}
pub fn remove_path_and_get_filename(file_path: &str) -> Option<String> {
let path = Path::new(file_path);
path.file_name()
.map(|name| name.to_string_lossy().into_owned())
}
pub fn get_directory_path(file_path: &str) -> Option<String> {
let path = Path::new(file_path);
path.parent()
.map(|p| p.to_string_lossy().into_owned())
}
#[cfg(test)]
mod tests {
use std::env;
use super::*;
use serial_test::serial;
use crate::env::{get, set};
fn setup() {
env::remove_var("RUST_PROFILE");
}
fn teardown() {
env::remove_var("RUST_PROFILE");
}
#[test]
#[serial]
fn test_remove_extension() {
setup();
let a = "apm-bigdata/flower-device/1111|2222|3333|4444.csv";
let b= remove_extension(a);
//println!("테스트 중: value = {}", b);
assert!(b.eq("apm-bigdata/flower-device/1111|2222|3333|4444"));
teardown();
}
#[test]
#[serial]
fn test_remove_path_and_get_filename() {
setup();
let a = "apm-bigdata/flower-device/1111|2222|3333|4444.csv";
let b= remove_path_and_get_filename(a).unwrap();
//println!("테스트 중: value = {}", b);
assert!(b.eq("1111|2222|3333|4444.csv"));
teardown();
}
#[test]
#[serial]
fn test_get_directory_path() {
setup();
let a = "apm-bigdata/flower-device/1111|2222|3333|4444.csv";
let b= get_directory_path(a).unwrap();
println!("테스트 중: value = {}", b);
assert!(b.eq("apm-bigdata/flower-device"));
teardown();
}
}
Loading…
Cancel
Save