Skip to content

Commit

Permalink
added test cases for update module driver
Browse files Browse the repository at this point in the history
Signed-off-by: Abhishek Kumar <abhishek22512@gmail.com>
  • Loading branch information
octonawish-akcodes committed Feb 7, 2024
1 parent 1f56f64 commit 56d3878
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 3 deletions.
2 changes: 1 addition & 1 deletion kclvm/driver/src/kpm_metadata.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{get_path_for_executable, kcl, lookup_the_nearest_file_dir};
use crate::lib::{get_path_for_executable, kcl, lookup_the_nearest_file_dir};
use anyhow::{bail, Ok, Result};
use kclvm_parser::LoadProgramOptions;
use serde::{Deserialize, Serialize};
Expand Down
2 changes: 1 addition & 1 deletion kclvm/driver/src/kpm_update.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use anyhow::{bail, Result};
use std::{path::PathBuf, process::Command};
use crate::{probe, lookup_the_nearest_file_dir, kcl};
use crate::lib::{probe, lookup_the_nearest_file_dir, kcl};

const MANIFEST_FILE: &str = "kcl.mod";

Expand Down
7 changes: 7 additions & 0 deletions kclvm/driver/src/test_data/kpm_update/kcl.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "kpm_update"
edition = "0.0.1"
version = "0.0.1"

[dependencies]
k8s = "1.29"
Empty file.
46 changes: 45 additions & 1 deletion kclvm/driver/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ use kclvm_parser::LoadProgramOptions;
use walkdir::WalkDir;

use crate::arguments::parse_key_value_pair;
use crate::kpm_metadata::{fetch_metadata, fill_pkg_maps_for_k_file, lookup_the_nearest_file_dir};
use crate::kpm_metadata::{fetch_metadata};
use crate::kpm_update::{update_kcl_module};
use crate::{canonicalize_input_files, expand_input_files, get_pkg_list};
use crate::lib::{fill_pkg_maps_for_k_file, lookup_the_nearest_file_dir};

#[test]
fn test_canonicalize_input_files() {
Expand Down Expand Up @@ -379,3 +381,45 @@ fn test_get_pkg_list() {
3
);
}

#[test]
fn test_lookup_the_nearest_file_dir() {
let path = PathBuf::from(".")
.join("src")
.join("test_data")
.join("kpm_update");
let result = lookup_the_nearest_file_dir(path.clone(), "kcl.mod");
assert!(result.is_some());
assert_eq!(
result.unwrap().display().to_string(),
path.canonicalize().unwrap().display().to_string()
);

let main_path = path.join("subdir").join("main.k");
let result = lookup_the_nearest_file_dir(main_path, "kcl.mod");
assert!(result.is_some());
assert_eq!(
result.unwrap().display().to_string(),
path.canonicalize().unwrap().display().to_string()
);
}

fn test_fetch_mod_metadata() {
let path = PathBuf::from(".")
.join("src")
.join("test_data")
.join("kpm_update");

let update_mod = update_kcl_module(path.clone());
// Show more information when the test fails.
println!("{:?}", update_mod);
assert!(!update_mod.is_err());
let pkgs = metadata.unwrap().packages.clone();
assert_eq!(pkgs.len(), 1);
}

#[test]
fn test_update_module() {
test_fetch_mod_metadata();
println!("test_fetch_metadata() passed");
}

0 comments on commit 56d3878

Please sign in to comment.