diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 98fffdc..bc4e2ff 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -276,8 +276,8 @@ jobs: # Test help shows new commands echo "Testing: help shows stop/start commands" - $BINARY_PATH --help | grep -q "stop" && echo "✅ stop command documented" || echo "❌ stop command missing" - $BINARY_PATH --help | grep -q "start" && echo "✅ start command documented" || echo "❌ start command missing" + $BINARY_PATH breeder --help | grep -q "stop" && echo "✅ stop command documented" || echo "❌ stop command missing" + $BINARY_PATH breeder --help | grep -q "start" && echo "✅ start command documented" || echo "❌ start command missing" echo "Testing: breeder purge --help shows --force flag" $BINARY_PATH breeder purge --help | grep -q "force" && echo "✅ --force flag documented in purge" || echo "❌ --force flag missing from purge" @@ -321,6 +321,54 @@ jobs: $BINARY_PATH --hostname=localhost --port=4010 --debug breeder list echo "✅ --debug flag works" + # === Error Handling Tests === + echo "" + echo "=== Testing Error Handling ===" + + # Test missing file + echo "Testing: missing file error" + if $BINARY_PATH --hostname=localhost --port=4010 breeder create --name=test --file=nonexistent.yml 2>/dev/null; then + echo "❌ Should have failed on missing file" + exit 1 + else + echo "✅ Failed on missing file as expected" + fi + + # Test missing required argument + echo "Testing: missing --id argument" + if $BINARY_PATH --hostname=localhost --port=4010 breeder show 2>/dev/null; then + echo "❌ Should have failed on missing --id" + exit 1 + else + echo "✅ Failed on missing --id as expected" + fi + + # === Output Format Tests === + echo "" + echo "=== Testing Output Formats ===" + + echo "Testing: JSON output format" + JSON_OUTPUT=$($BINARY_PATH --hostname=localhost --port=4010 --output=json breeder list) + if echo "$JSON_OUTPUT" | grep -q '"id"\|"name"\|"status"'; then + echo "✅ JSON output contains expected fields" + else + echo "❌ JSON output missing expected fields" + fi + + echo "Testing: YAML output format" + YAML_OUTPUT=$($BINARY_PATH --hostname=localhost --port=4010 --output=yaml breeder list) + if echo "$YAML_OUTPUT" | grep -q -e '^-' -e 'id:' -e 'name:'; then + echo "✅ YAML output contains expected fields" + else + echo "❌ YAML output missing expected fields" + fi + + echo "Testing: JSON output for breeder show" + $BINARY_PATH --hostname=localhost --port=4010 --output=json breeder show --id=550e8400-e29b-41d4-a716-446655440000 + + echo "Testing: YAML output for credential list" + $BINARY_PATH --hostname=localhost --port=4010 --output=yaml credential list + - name: Cleanup Prism container if: always() run: | diff --git a/README.md b/README.md index 6cd137c..c592bcd 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Godon CLI -A Nim-based CLI tool for controlling and managing the Godon optimizer breeders via the Godon Control API. +A Rust-based CLI tool for controlling and managing the Godon optimizer breeders via the Godon Control API. ## Features @@ -146,7 +146,7 @@ Create a YAML configuration file `credential.yaml`: ```yaml name: "production_ssh_key" -credential_type: "ssh_private_key" +credentialType: "ssh_private_key" description: "SSH key for production servers" content: | -----BEGIN RSA PRIVATE KEY----- diff --git a/src/main.rs b/src/main.rs index 27fbbeb..0ac82bf 100644 --- a/src/main.rs +++ b/src/main.rs @@ -266,13 +266,17 @@ async fn handle_breeder_command(client: &GodonClient, cmd: BreederCommands, outp let response = client.update_breeder_from_yaml(&content).await; if response.success { - if matches!(output, OutputFormat::Text) { - if let Some(ref data) = response.data { - let id = data.get("id").and_then(|v| v.as_str()).unwrap_or("unknown"); - println!("Breeder updated successfully: {}", id); + if let Some(data) = response.data { + match data.get("id").and_then(|v| v.as_str()) { + Some(id) => { + if matches!(output, OutputFormat::Text) { + println!("Breeder updated successfully: {}", id); + } else { + format_output(&data, output); + } + } + None => write_error("Unexpected response format: missing 'id' field"), } - } else if let Some(data) = response.data { - format_output(&data, output); } } else { write_error(response.error.as_deref().unwrap_or("Unknown error"));