Skip to content

Commit

Permalink
fix: tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kainlite committed Jan 12, 2025
1 parent 90cd958 commit 8880c2d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 59 deletions.
19 changes: 16 additions & 3 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,21 @@ jobs:
steps:
- uses: actions/checkout@v4

- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: stable
target: x86_64-unknown-linux-gnu
override: true

- name: Create k8s Kind Cluster
uses: helm/kind-action@v1

- name: Create secret
run: |
ssh-keygen -t rsa -b 4096 -f /tmp/id_rsa <<< y
kubectl create ns myns
kubectl create secret generic ssh-key -n myns --from-file=ssh-privatekey=/tmp/id_rsa
- name: run tests
run: docker run $(docker build -q -f Dockerfile.test .) cargo test
run: cargo test
16 changes: 0 additions & 16 deletions Dockerfile.test

This file was deleted.

5 changes: 2 additions & 3 deletions src/configuration/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,6 @@ async fn get_notifications_endpoint(name: &str, namespace: &str) -> Option<Strin
#[tracing::instrument(name = "process_deployment", skip(entry), fields())]
pub async fn process_deployment(entry: Entry) -> Result<(), String> {
info!("Processing: {}/{}", &entry.namespace, &entry.name);
if !entry.config.enabled {
warn!("Config is disabled for deployment: {}", &entry.name);
}

let endpoint = get_notifications_endpoint(
&entry.config.notifications_secret_name.unwrap_or_default(),
Expand Down Expand Up @@ -319,6 +316,8 @@ pub async fn reconcile(State(store): State<Cache>) -> Json<Vec<String>> {
.iter()
.filter_map(|d| deployment_to_entry(d))
.collect();

println!("{:?}", data);
let mut handles: Vec<_> = vec![];

for entry in &data {
Expand Down
68 changes: 31 additions & 37 deletions tests/configuration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,15 @@ mod tests {
let entries = response.0;

assert_eq!(entries.len(), 1);
assert_eq!(entries[0].name, "test-app");
assert_eq!(entries[0].namespace, "default");
assert_eq!(entries[0].container, "my-container");
assert_eq!(entries[0].version, "1.0.0");
let entry1 = entries
.iter()
.find(|e| {
e.to_string()
== "Deployment: test-app is up to date, proceeding to next deployment..."
})
.unwrap();

assert!(entry1.to_string().contains("test-app"));
}

#[tokio::test]
Expand Down Expand Up @@ -404,45 +409,34 @@ mod tests {
// Call reconcile endpoint
let response = reconcile(State(reader)).await;
let entries = response.0;
println!("{:?}", entries);

// Verify the results
// Should only include valid deployments (enabled and disabled)
assert_eq!(entries.len(), 2);
// Should only include valid deployments and enabled
assert_eq!(entries.len(), 1);

// Check first deployment (enabled)
let entry1 = entries.iter().find(|e| e.name == "test-app1").unwrap();
assert_eq!(entry1.namespace, "default");
assert_eq!(entry1.container, "container1");
assert_eq!(entry1.version, "1.0.0");
assert!(entry1.config.enabled);
assert_eq!(entry1.config.app_repository, "https://github.com/org/app1");
assert_eq!(
entry1.config.notifications_secret_name,
Some(String::from("test-app1-notifications"))
);
assert_eq!(
entry1.config.notifications_secret_namespace,
Some(String::from("default"))
);

// Check second deployment (disabled)
let entry2 = entries.iter().find(|e| e.name == "test-app2").unwrap();
assert_eq!(entry2.namespace, "default");
assert_eq!(entry2.container, "container2");
assert_eq!(entry2.version, "2.0.0");
assert!(!entry2.config.enabled);
assert_eq!(entry2.config.app_repository, "https://github.com/org/app2");
assert_eq!(
entry2.config.notifications_secret_name,
Some(String::from("test-app1-notifications"))
);
assert_eq!(
entry2.config.notifications_secret_namespace,
Some(String::from("default"))
);
let entry1 = entries
.iter()
.find(|e| {
e.to_string()
== "Deployment: test-app1 is up to date, proceeding to next deployment..."
})
.unwrap();

assert!(entry1.to_string().contains("test-app1"));

// Check that the second deployment (disabled) is not present
assert!(entries
.iter()
.find(|e| { e.to_string() == "test-app2" })
.is_none());

// Verify the invalid deployment is not included
assert!(entries.iter().find(|e| e.name == "test-app3").is_none());
assert!(entries
.iter()
.find(|e| e.to_string() == "test-app3")
.is_none());
}

#[tokio::test]
Expand Down

0 comments on commit 8880c2d

Please sign in to comment.