|
| 1 | +use crate::{run_command, TWOLITER_PATH}; |
| 2 | +use duct::cmd; |
| 3 | +use std::path::Path; |
| 4 | +use tempfile::TempDir; |
| 5 | +use which::which; |
| 6 | + |
| 7 | +/// Create a test project by cloning bottlerocket |
| 8 | +async fn create_test_project() -> TempDir { |
| 9 | + let tmp_dir = TempDir::new().expect("failed to create temporary directory"); |
| 10 | + let git = which("git").expect("failed to find git"); |
| 11 | + let inside = tmp_dir.path().to_str().unwrap(); |
| 12 | + |
| 13 | + cmd!( |
| 14 | + git, |
| 15 | + "clone", |
| 16 | + "--depth", |
| 17 | + "1", |
| 18 | + "https://github.com/bottlerocket-os/bottlerocket.git", |
| 19 | + inside |
| 20 | + ) |
| 21 | + .run() |
| 22 | + .expect("failed to clone bottlerocket"); |
| 23 | + |
| 24 | + tmp_dir |
| 25 | +} |
| 26 | + |
| 27 | +/// Run twoliter make with a specific target |
| 28 | +fn twoliter_make( |
| 29 | + project_dir: &Path, |
| 30 | + target: &str, |
| 31 | + variant: &str, |
| 32 | + arch: &str, |
| 33 | +) -> std::process::Output { |
| 34 | + let cargo_home = project_dir.join(".cargo"); |
| 35 | + std::fs::create_dir_all(&cargo_home).unwrap(); |
| 36 | + |
| 37 | + run_command( |
| 38 | + TWOLITER_PATH, |
| 39 | + [ |
| 40 | + "make", |
| 41 | + "--project-path", |
| 42 | + project_dir.join("Twoliter.toml").to_str().unwrap(), |
| 43 | + "--cargo-home", |
| 44 | + cargo_home.to_str().unwrap(), |
| 45 | + "--arch", |
| 46 | + arch, |
| 47 | + target, |
| 48 | + ], |
| 49 | + [("BUILDSYS_VARIANT", variant)], |
| 50 | + ) |
| 51 | +} |
| 52 | + |
| 53 | +/// Test that build-variant runs successfully via twoliter make. |
| 54 | +#[tokio::test] |
| 55 | +#[ignore] |
| 56 | +async fn test_twoliter_build_variant() { |
| 57 | + let bob_src = create_test_project().await; |
| 58 | + let project_path = bob_src.path().join("Twoliter.toml"); |
| 59 | + let arch = "x86_64"; |
| 60 | + let variant = "aws-ecs-2"; |
| 61 | + |
| 62 | + // Update |
| 63 | + let output = run_command( |
| 64 | + TWOLITER_PATH, |
| 65 | + ["update", "--project-path", project_path.to_str().unwrap()], |
| 66 | + [], |
| 67 | + ); |
| 68 | + assert!(output.status.success(), "twoliter update failed"); |
| 69 | + |
| 70 | + // Fetch |
| 71 | + let output = run_command( |
| 72 | + TWOLITER_PATH, |
| 73 | + [ |
| 74 | + "fetch", |
| 75 | + "--project-path", |
| 76 | + project_path.to_str().unwrap(), |
| 77 | + "--arch", |
| 78 | + arch, |
| 79 | + ], |
| 80 | + [], |
| 81 | + ); |
| 82 | + assert!(output.status.success(), "twoliter fetch failed"); |
| 83 | + |
| 84 | + // Build variant |
| 85 | + let output = twoliter_make(bob_src.path(), "build-variant", variant, arch); |
| 86 | + assert!( |
| 87 | + output.status.success(), |
| 88 | + "twoliter make build-variant failed: {}", |
| 89 | + String::from_utf8_lossy(&output.stderr) |
| 90 | + ); |
| 91 | +} |
| 92 | + |
| 93 | +/// Test that repack-variant runs successfully via twoliter make. |
| 94 | +/// This requires a previously built variant image to repack. |
| 95 | +#[tokio::test] |
| 96 | +#[ignore] |
| 97 | +async fn test_twoliter_repack_variant() { |
| 98 | + let bob_src = create_test_project().await; |
| 99 | + let project_path = bob_src.path().join("Twoliter.toml"); |
| 100 | + let arch = "x86_64"; |
| 101 | + let variant = "aws-ecs-2"; |
| 102 | + |
| 103 | + // Update |
| 104 | + let output = run_command( |
| 105 | + TWOLITER_PATH, |
| 106 | + ["update", "--project-path", project_path.to_str().unwrap()], |
| 107 | + [], |
| 108 | + ); |
| 109 | + assert!(output.status.success(), "twoliter update failed"); |
| 110 | + |
| 111 | + // Fetch |
| 112 | + let output = run_command( |
| 113 | + TWOLITER_PATH, |
| 114 | + [ |
| 115 | + "fetch", |
| 116 | + "--project-path", |
| 117 | + project_path.to_str().unwrap(), |
| 118 | + "--arch", |
| 119 | + arch, |
| 120 | + ], |
| 121 | + [], |
| 122 | + ); |
| 123 | + assert!(output.status.success(), "twoliter fetch failed"); |
| 124 | + |
| 125 | + // First build the variant |
| 126 | + let output = twoliter_make(bob_src.path(), "build-variant", variant, arch); |
| 127 | + assert!( |
| 128 | + output.status.success(), |
| 129 | + "twoliter make build-variant failed: {}", |
| 130 | + String::from_utf8_lossy(&output.stderr) |
| 131 | + ); |
| 132 | + |
| 133 | + // Then repack it |
| 134 | + let output = twoliter_make(bob_src.path(), "repack-variant", variant, arch); |
| 135 | + assert!( |
| 136 | + output.status.success(), |
| 137 | + "twoliter make repack-variant failed: {}", |
| 138 | + String::from_utf8_lossy(&output.stderr) |
| 139 | + ); |
| 140 | +} |
0 commit comments