-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add integration test for
twoliter update
- Loading branch information
Showing
10 changed files
with
187 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
name: "Install crane" | ||
description: "Installs crane for use in testing." | ||
inputs: | ||
crane-version: | ||
description: "Version of crane to install" | ||
required: false | ||
default: latest | ||
install-dir: | ||
description: "Directory to install crane" | ||
required: false | ||
default: $HOME/.crane | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- shell: bash | ||
run: | | ||
mkdir -p ${{ inputs.install-dir }} | ||
VERSION=${{ inputs.crane-version }} | ||
if [[ "${VERSION}" == "latest" ]]; then | ||
VERSION=$(curl -s "https://api.github.com/repos/google/go-containerregistry/releases/latest" | jq -r '.tag_name') | ||
fi | ||
case ${{ runner.arch }} in | ||
X64) | ||
ARCH=x86_64 | ||
;; | ||
ARM64) | ||
ARCH=arm64 | ||
;; | ||
esac | ||
curl -sL "https://github.com/google/go-containerregistry/releases/download/${VERSION}/go-containerregistry_Linux_${ARCH}.tar.gz" > go-containerregistry.tar.gz | ||
tar -zxvf go-containerregistry.tar.gz -C "${{ inputs.install-dir }}" crane | ||
echo "${{ inputs.install-dir }}" >> "${GITHUB_PATH}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
[package] | ||
name = "integration-tests" | ||
version = "0.1.0" | ||
edition = "2021" | ||
license = "MIT OR Apache-2.0" | ||
|
||
[dev-dependencies] | ||
tokio = { version = "1", default-features = false, features = ["process", "fs", "rt-multi-thread"] } | ||
twoliter = { version = "0", path = "../../twoliter", artifact = [ "bin:twoliter" ] } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
#![cfg(test)] | ||
|
||
use std::ffi::OsStr; | ||
use std::path::PathBuf; | ||
use tokio::process::Command; | ||
|
||
mod twoliter_update; | ||
|
||
pub const TWOLITER_PATH: &'static str = env!("CARGO_BIN_FILE_TWOLITER"); | ||
|
||
pub fn test_projects_dir() -> PathBuf { | ||
let mut p = PathBuf::from(env!("CARGO_MANIFEST_DIR")); | ||
p.pop(); | ||
p.join("projects") | ||
} | ||
|
||
pub async fn run_command<I, S, E>(cmd: S, args: I, env: E) -> std::process::Output | ||
where | ||
I: IntoIterator<Item = S>, | ||
E: IntoIterator<Item = (S, S)>, | ||
S: AsRef<OsStr>, | ||
{ | ||
let args: Vec<S> = args.into_iter().collect(); | ||
|
||
println!( | ||
"Executing '{}' with args [{}]", | ||
cmd.as_ref().to_string_lossy(), | ||
args.iter() | ||
.map(|arg| format!("'{}'", arg.as_ref().to_string_lossy())) | ||
.collect::<Vec<_>>() | ||
.join(", ") | ||
); | ||
|
||
let output = Command::new(cmd) | ||
.args(args.into_iter()) | ||
.envs(env.into_iter()) | ||
.output() | ||
.await | ||
.expect("failed to execute process"); | ||
|
||
println!("stdout: {}", String::from_utf8_lossy(&output.stdout)); | ||
println!("stderr: {}", String::from_utf8_lossy(&output.stderr)); | ||
output | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use super::{run_command, test_projects_dir, TWOLITER_PATH}; | ||
|
||
const EXPECTED_LOCKFILE: &str = r#"schema-version = 1 | ||
release-version = "1.0.0" | ||
digest = "m/6DbBacnIBHMo34GCuzA4pAHzrnQJ2G/XJMMguZXjw=" | ||
[sdk] | ||
name = "bottlerocket-sdk" | ||
version = "0.42.0" | ||
vendor = "bottlerocket" | ||
source = "public.ecr.aws/bottlerocket/bottlerocket-sdk:v0.42.0" | ||
digest = "myHHKE41h9qfeyR6V6HB0BfiLPwj3QEFLUFy4TXcR10=" | ||
[[kit]] | ||
name = "bottlerocket-core-kit" | ||
version = "2.0.0" | ||
vendor = "custom-vendor" | ||
source = "public.ecr.aws/bottlerocket/bottlerocket-core-kit:v2.0.0" | ||
digest = "vlTsAAbSCzXFZofVmw8pLLkRjnG/y8mtb2QsQBSz1zk=" | ||
"#; | ||
|
||
#[tokio::test] | ||
#[ignore] | ||
/// Generates a Twoliter.lock file for the `external-kit` project using docker | ||
async fn test_twoliter_update_docker() { | ||
let external_kit = test_projects_dir().join("external-kit"); | ||
|
||
let lockfile = external_kit.join("Twoliter.lock"); | ||
tokio::fs::remove_file(&lockfile).await.ok(); | ||
|
||
let output = run_command( | ||
TWOLITER_PATH, | ||
[ | ||
"update", | ||
"--project-path", | ||
external_kit.join("Twoliter.toml").to_str().unwrap(), | ||
], | ||
[("TWOLITER_KIT_IMAGE_TOOL", "docker")], | ||
) | ||
.await; | ||
|
||
assert!(output.status.success()); | ||
|
||
let lock_contents = tokio::fs::read_to_string(&lockfile).await.unwrap(); | ||
assert_eq!(lock_contents, EXPECTED_LOCKFILE); | ||
|
||
tokio::fs::remove_file(&lockfile).await.ok(); | ||
} | ||
|
||
#[tokio::test] | ||
#[ignore] | ||
/// Generates a Twoliter.lock file for the `external-kit` project using crane | ||
async fn test_twoliter_update_crane() { | ||
let external_kit = test_projects_dir().join("external-kit"); | ||
|
||
let lockfile = external_kit.join("Twoliter.lock"); | ||
tokio::fs::remove_file(&lockfile).await.ok(); | ||
|
||
let output = run_command( | ||
TWOLITER_PATH, | ||
[ | ||
"update", | ||
"--project-path", | ||
external_kit.join("Twoliter.toml").to_str().unwrap(), | ||
], | ||
[("TWOLITER_KIT_IMAGE_TOOL", "crane")], | ||
) | ||
.await; | ||
|
||
assert!(output.status.success()); | ||
|
||
let lock_contents = tokio::fs::read_to_string(&lockfile).await.unwrap(); | ||
assert_eq!(lock_contents, EXPECTED_LOCKFILE); | ||
|
||
tokio::fs::remove_file(&lockfile).await.ok(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,13 @@ | ||
schema-version = 1 | ||
release-version = "1.0.0" | ||
|
||
[sdk] | ||
name = "bottlerocket-sdk" | ||
vendor = "bottlerocket" | ||
version = "0.41.0" | ||
|
||
[vendor.bottlerocket] | ||
registry = "public.ecr.aws/bottlerocket" | ||
|
||
[vendor.custom-vendor] | ||
# We need to figure out how we can do integration testing with this | ||
registry = "public.ecr.aws/bottlerocket" | ||
|
||
[[kit]] | ||
name = "core-kit" | ||
version = "0.1.0" | ||
name = "bottlerocket-core-kit" | ||
version = "2.0.0" | ||
vendor = "custom-vendor" |