use super::*;
#[test]
fn test_dockerfile_lint_command_basic() {
let temp_dir = TempDir::new().unwrap();
let dockerfile = temp_dir.path().join("Dockerfile");
fs::write(&dockerfile, "FROM ubuntu:20.04\nRUN apt-get update").unwrap();
let result = dockerfile_lint_command(&dockerfile, LintFormat::Human, None);
let _ = result;
}
#[test]
fn test_dockerfile_lint_command_with_rules() {
let temp_dir = TempDir::new().unwrap();
let dockerfile = temp_dir.path().join("Dockerfile");
fs::write(&dockerfile, "FROM ubuntu:20.04\nRUN apt-get update").unwrap();
let result = dockerfile_lint_command(&dockerfile, LintFormat::Json, Some("DOCKER001"));
let _ = result;
}
#[test]
fn test_purify_dockerfile_content_basic() {
let dockerfile = "FROM ubuntu:20.04\nRUN apt-get update";
let result = purify_dockerfile(dockerfile, false);
assert!(result.is_ok());
}
#[test]
fn test_purify_dockerfile_content_skip_user() {
let dockerfile = "FROM ubuntu:20.04\nRUN echo hello";
let result = purify_dockerfile(dockerfile, true);
assert!(result.is_ok());
}
#[test]
fn test_purify_dockerfile_content_with_cleanup() {
let dockerfile = "FROM ubuntu:20.04\nRUN apt-get update && apt-get install -y curl";
let result = purify_dockerfile(dockerfile, false);
assert!(result.is_ok());
let purified = result.unwrap();
assert!(purified.contains("apt-get") || purified.contains("FROM"));
}
#[test]
fn test_logic_find_devcontainer_json_exists() {
let temp_dir = TempDir::new().unwrap();
let devcontainer_dir = temp_dir.path().join(".devcontainer");
fs::create_dir_all(&devcontainer_dir).unwrap();
let json_path = devcontainer_dir.join("devcontainer.json");
fs::write(&json_path, r#"{"name": "test"}"#).unwrap();
let result = logic_find_devcontainer_json(temp_dir.path());
assert!(result.is_ok());
}
#[test]
fn test_logic_find_devcontainer_json_not_exists() {
let temp_dir = TempDir::new().unwrap();
let result = logic_find_devcontainer_json(temp_dir.path());
assert!(result.is_err());
}
#[test]
fn test_dockerfile_profile_command_human() {
let temp_dir = TempDir::new().unwrap();
let input = temp_dir.path().join("Dockerfile");
fs::write(
&input,
"FROM python:3.11-slim\nRUN pip install flask\nCOPY . /app\n",
)
.unwrap();
let result = dockerfile_profile_command(
&input,
true, true, false, false, false, None, "30s", None, false, false, ReportFormat::Human,
);
assert!(result.is_ok());
}
#[test]
fn test_dockerfile_profile_command_full_human() {
let temp_dir = TempDir::new().unwrap();
let input = temp_dir.path().join("Dockerfile");
fs::write(
&input,
"FROM ubuntu:22.04\nRUN apt-get update && apt-get install -y curl\nCOPY . /app\n",
)
.unwrap();
let result = dockerfile_profile_command(
&input,
false,
false,
false,
false,
false,
None,
"30s",
None,
false,
true, ReportFormat::Human,
);
assert!(result.is_ok());
}
#[test]
fn test_dockerfile_profile_command_json() {
let temp_dir = TempDir::new().unwrap();
let input = temp_dir.path().join("Dockerfile");
fs::write(&input, "FROM alpine:3.18\nRUN apk add curl\n").unwrap();
let result = dockerfile_profile_command(
&input,
false,
false,
false,
false,
false,
None,
"30s",
None,
false,
false,
ReportFormat::Json,
);
assert!(result.is_ok());
}
#[test]
fn test_dockerfile_profile_command_markdown() {
let temp_dir = TempDir::new().unwrap();
let input = temp_dir.path().join("Dockerfile");
fs::write(&input, "FROM node:20-alpine\nCOPY . /app\n").unwrap();
let result = dockerfile_profile_command(
&input,
false,
false,
false,
false,
false,
None,
"30s",
None,
false,
false,
ReportFormat::Markdown,
);
assert!(result.is_ok());
}
#[test]
fn test_dockerfile_profile_command_coursera_with_limits() {
let temp_dir = TempDir::new().unwrap();
let input = temp_dir.path().join("Dockerfile");
fs::write(&input, "FROM python:3.11-slim\nRUN pip install flask\n").unwrap();
let result = dockerfile_profile_command(
&input,
true,
true,
true,
true,
true,
None,
"30s",
Some(LintProfileArg::Coursera),
true, false,
ReportFormat::Human,
);
assert!(result.is_ok());
}
#[test]
fn test_dockerfile_size_check_command_human_basic() {
let temp_dir = TempDir::new().unwrap();
let input = temp_dir.path().join("Dockerfile");
fs::write(&input, "FROM alpine:3.18\nRUN apk add curl\n").unwrap();
let result = dockerfile_size_check_command(
&input,
false, false, false, false, false, None, false, None, false, ReportFormat::Human,
);
assert!(result.is_ok());
}
#[test]
fn test_dockerfile_size_check_command_verbose_with_bloat() {
let temp_dir = TempDir::new().unwrap();
let input = temp_dir.path().join("Dockerfile");
fs::write(
&input,
"FROM ubuntu:22.04\nRUN apt-get update && apt-get install -y curl wget git\n",
)
.unwrap();
let result = dockerfile_size_check_command(
&input,
true, true, true, false,
false,
None,
false,
None,
true, ReportFormat::Human,
);
assert!(result.is_ok());
}
#[test]
fn test_dockerfile_size_check_command_json() {
let temp_dir = TempDir::new().unwrap();
let input = temp_dir.path().join("Dockerfile");
fs::write(&input, "FROM python:3.11\nRUN pip install flask\n").unwrap();
let result = dockerfile_size_check_command(
&input,
false,
false,
false,
false,
false,
None,
false,
None,
false,
ReportFormat::Json,
);
assert!(result.is_ok());
}
#[test]
fn test_dockerfile_size_check_command_markdown() {
let temp_dir = TempDir::new().unwrap();
let input = temp_dir.path().join("Dockerfile");
fs::write(&input, "FROM node:20\nCOPY . /app\n").unwrap();
let result = dockerfile_size_check_command(
&input,
false,
false,
false,
false,
false,
None,
false,
None,
false,
ReportFormat::Markdown,
);
assert!(result.is_ok());
}
#[test]
fn test_dockerfile_size_check_command_with_coursera_profile() {
let temp_dir = TempDir::new().unwrap();
let input = temp_dir.path().join("Dockerfile");
fs::write(&input, "FROM python:3.11-slim\nRUN pip install flask\n").unwrap();
let result = dockerfile_size_check_command(
&input,
true,
true,
true,
false,
false,
Some(LintProfileArg::Coursera),
false,
None,
false,
ReportFormat::Human,
);
assert!(result.is_ok());
}
#[test]
fn test_dockerfile_size_check_command_custom_max_size_gb() {
let temp_dir = TempDir::new().unwrap();
let input = temp_dir.path().join("Dockerfile");
fs::write(&input, "FROM alpine:3.18\nRUN echo hello\n").unwrap();
let result = dockerfile_size_check_command(
&input,
false,
false,
false,
false,
false,
None,
false,
Some("5GB"),
false,
ReportFormat::Human,
);
assert!(result.is_ok());
}
#[test]
fn test_dockerfile_size_check_command_custom_max_size_mb() {
let temp_dir = TempDir::new().unwrap();
let input = temp_dir.path().join("Dockerfile");
fs::write(&input, "FROM alpine:3.18\nRUN echo hello\n").unwrap();
let result = dockerfile_size_check_command(
&input,
false,
false,
false,
false,
false,
None,
false,
Some("500MB"),
false,
ReportFormat::Human,
);
assert!(result.is_ok());
}
#[test]
include!("command_tests_dockerfile_tests_dockerfile.rs");