-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
integ: run push and pull from local registry when testing
Co-authored-by: Jarrett Tierney <[email protected]>
- Loading branch information
Showing
9 changed files
with
207 additions
and
57 deletions.
There are no files selected for viewing
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
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,74 +1,134 @@ | ||
use super::{run_command, test_projects_dir, TWOLITER_PATH}; | ||
|
||
const EXPECTED_LOCKFILE: &str = r#"schema-version = 1 | ||
[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=" | ||
use super::{run_command, test_projects_dir, KitRegistry, TWOLITER_PATH}; | ||
|
||
const INFRA_TOML: &str = r#" | ||
[vendor.bottlerocket] | ||
registry = "localhost:5000" | ||
"#; | ||
|
||
const TWOLITER_OVERRIDE: &str = r#" | ||
[custom-vendor.core-kit] | ||
registry = "localhost:5000" | ||
name = "core-kit-overridden" | ||
"#; | ||
|
||
#[tokio::test] | ||
#[test] | ||
#[ignore] | ||
/// Generates a Twoliter.lock file for the `external-kit` project using docker | ||
async fn test_twoliter_update_docker() { | ||
/// Generates a Twoliter.lock file for the `external-kit` project using crane | ||
fn test_twoliter_build_and_update() { | ||
let external_kit = test_projects_dir().join("external-kit"); | ||
|
||
let lockfile = external_kit.join("Twoliter.lock"); | ||
tokio::fs::remove_file(&lockfile).await.ok(); | ||
std::fs::remove_file(&lockfile).ok(); | ||
let override_file = external_kit.join("Twoliter.override"); | ||
std::fs::remove_file(&override_file).ok(); | ||
|
||
// Build & push a local kit to the registry | ||
let registry = KitRegistry::new(); | ||
LocalKit::build(®istry); | ||
|
||
// Point twoliter to the local registry as an override | ||
std::fs::write(&override_file, TWOLITER_OVERRIDE).unwrap(); | ||
let output = run_command( | ||
TWOLITER_PATH, | ||
[ | ||
"update", | ||
"--project-path", | ||
external_kit.join("Twoliter.toml").to_str().unwrap(), | ||
], | ||
[("TWOLITER_KIT_IMAGE_TOOL", "docker")], | ||
) | ||
.await; | ||
[ | ||
("TWOLITER_KIT_IMAGE_TOOL", "crane"), | ||
("SSL_CERT_FILE", registry.cert_file().to_str().unwrap()), | ||
], | ||
); | ||
|
||
assert!(output.status.success()); | ||
|
||
let lock_contents = tokio::fs::read_to_string(&lockfile).await.unwrap(); | ||
assert_eq!(lock_contents, EXPECTED_LOCKFILE); | ||
// Assert that we successfully create a lock | ||
let lock_contents = std::fs::read_to_string(&lockfile).unwrap(); | ||
let parsed: toml::Value = toml::from_str(&lock_contents).unwrap(); | ||
let kits = parsed | ||
.as_table() | ||
.unwrap() | ||
.get("kit") | ||
.unwrap() | ||
.as_array() | ||
.unwrap(); | ||
|
||
assert_eq!(kits.len(), 1); | ||
let core_kit = kits[0].as_table().unwrap(); | ||
assert_eq!(core_kit.get("name").unwrap().as_str().unwrap(), "core-kit"); | ||
assert_eq!(core_kit.get("version").unwrap().as_str().unwrap(), "1.0.0"); | ||
assert_eq!( | ||
core_kit.get("vendor").unwrap().as_str().unwrap(), | ||
"custom-vendor" | ||
); | ||
assert_eq!( | ||
core_kit.get("source").unwrap().as_str().unwrap(), | ||
"definitely-wont-resolve/core-kit:v1.0.0" | ||
); | ||
|
||
tokio::fs::remove_file(&lockfile).await.ok(); | ||
std::fs::remove_file(&lockfile).ok(); | ||
std::fs::remove_file(&override_file).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"); | ||
struct LocalKit; | ||
|
||
let lockfile = external_kit.join("Twoliter.lock"); | ||
tokio::fs::remove_file(&lockfile).await.ok(); | ||
impl LocalKit { | ||
fn build(registry: &KitRegistry) { | ||
let local_kit = test_projects_dir().join("local-kit"); | ||
|
||
let output = run_command( | ||
TWOLITER_PATH, | ||
[ | ||
"update", | ||
"--project-path", | ||
external_kit.join("Twoliter.toml").to_str().unwrap(), | ||
], | ||
[("TWOLITER_KIT_IMAGE_TOOL", "crane")], | ||
) | ||
.await; | ||
run_command( | ||
TWOLITER_PATH, | ||
[ | ||
"update", | ||
"--project-path", | ||
local_kit.join("Twoliter.toml").to_str().unwrap(), | ||
], | ||
[], | ||
); | ||
|
||
assert!(output.status.success()); | ||
run_command( | ||
TWOLITER_PATH, | ||
[ | ||
"fetch", | ||
"--project-path", | ||
local_kit.join("Twoliter.toml").to_str().unwrap(), | ||
], | ||
[], | ||
); | ||
|
||
let lock_contents = tokio::fs::read_to_string(&lockfile).await.unwrap(); | ||
assert_eq!(lock_contents, EXPECTED_LOCKFILE); | ||
run_command( | ||
TWOLITER_PATH, | ||
[ | ||
"build", | ||
"kit", | ||
"core-kit", | ||
"--project-path", | ||
local_kit.join("Twoliter.toml").to_str().unwrap(), | ||
], | ||
[], | ||
); | ||
|
||
std::fs::write(local_kit.join("Infra.toml"), INFRA_TOML).unwrap(); | ||
run_command( | ||
TWOLITER_PATH, | ||
[ | ||
"publish", | ||
"kit", | ||
"--project-path", | ||
local_kit.join("Twoliter.toml").to_str().unwrap(), | ||
"core-kit", | ||
"bottlerocket", | ||
"core-kit-overridden", | ||
], | ||
[("SSL_CERT_FILE", registry.cert_file().to_str().unwrap())], | ||
); | ||
} | ||
} | ||
|
||
tokio::fs::remove_file(&lockfile).await.ok(); | ||
impl Drop for LocalKit { | ||
fn drop(&mut self) { | ||
let local_kit = test_projects_dir().join("local-kit"); | ||
std::fs::remove_file(local_kit.join("Twoliter.lock")).ok(); | ||
std::fs::remove_file(local_kit.join("Infra.toml")).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 |
---|---|---|
|
@@ -8,3 +8,5 @@ | |
Test.toml | ||
testsys.kubeconfig | ||
Infra.toml | ||
Twoliter.lock | ||
Twoliter.override |
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 |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
Test.toml | ||
testsys.kubeconfig | ||
Infra.toml | ||
Twoliter.lock |
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