Skip to main content
Glama
box-terminate.exp13.7 kB
#!/usr/bin/env expect # Exit codes: # 0 - Test passed # 1 - Test failed # Set timeout for command execution set timeout 30 # Colors for output set GREEN "\033\[0;32m" set RED "\033\[0;31m" set YELLOW "\033\[1;33m" set BLUE "\033\[0;34m" set NC "\033\[0m" # Get the gbox binary path # Default to using the built binary in the parent directory set gbox_binary "../gbox" # If the built binary doesn't exist, fall back to system gbox if {![file exists $gbox_binary]} { set gbox_binary "gbox" } puts "${BLUE}Testing gbox box terminate command...${NC}" # Test 1: Basic box terminate command without arguments (should show error) puts "\n${YELLOW}Testing basic box terminate command without arguments...${NC}" puts "${BLUE}Running Test 1: Basic box terminate command without arguments${NC}" if {[catch { spawn $gbox_binary box terminate expect { -re "must specify either --all or a box ID" { puts "${GREEN}✓ Found expected error message for missing arguments${NC}" exp_continue } timeout { puts "${RED}✗ Timeout waiting for error message${NC}" exit 1 } eof { puts "${GREEN}✓ Error message displayed correctly${NC}" } } catch {close} } result]} { puts "${RED}✗ Test failed: $result${NC}" exit 1 } # Test 2: Help command for box terminate puts "\n${YELLOW}Testing help command for box terminate...${NC}" puts "${BLUE}Running Test 2: Help command for box terminate${NC}" if {[catch { spawn $gbox_binary box terminate --help expect { -re "Terminate a box by its ID" { puts "${GREEN}✓ Found help description${NC}" } timeout { puts "${RED}✗ Timeout waiting for help description${NC}" exit 1 } eof { puts "${RED}✗ Help command exited unexpectedly${NC}" exit 1 } } expect { -re "Flags:" { puts "${GREEN}✓ Found Flags section${NC}" } timeout { puts "${RED}✗ Timeout waiting for Flags section${NC}" exit 1 } } expect { -re "-o, --output.*Output format" { puts "${GREEN}✓ Found output flag description${NC}" } -re "-a, --all.*Terminate all boxes" { puts "${GREEN}✓ Found all flag description${NC}" } -re "-f, --force.*Force termination" { puts "${GREEN}✓ Found force flag description${NC}" } timeout { puts "${RED}✗ Timeout waiting for flag descriptions${NC}" exit 1 } } expect { eof { puts "${GREEN}✓ Help command completed successfully${NC}" } timeout { puts "${RED}✗ Timeout waiting for help completion${NC}" exit 1 } } catch {close} } result]} { puts "${RED}✗ Help test failed: $result${NC}" exit 1 } # Test 3: Terminate all boxes command puts "\n${YELLOW}Testing terminate all boxes command...${NC}" puts "${BLUE}Running Test 3: Terminate all boxes command${NC}" if {[catch { spawn $gbox_binary box terminate --all expect { -re "No boxes to terminate" { puts "${GREEN}✓ Found 'No boxes to terminate' message${NC}" exp_continue } -re "The following boxes will be terminated:" { puts "${GREEN}✓ Found boxes list for termination${NC}" exp_continue } -re "Are you sure you want to terminate all boxes\\? \\[y/N\\]" { puts "${GREEN}✓ Found confirmation prompt${NC}" send "y\r" exp_continue } timeout { puts "${RED}✗ Timeout waiting for terminate all output${NC}" exit 1 } eof { puts "${GREEN}✓ Terminate all command completed successfully${NC}" } } catch {close} } result]} { puts "${RED}✗ Terminate all test failed: $result${NC}" exit 1 } # Test 4: Terminate all boxes with force flag puts "\n${YELLOW}Testing terminate all boxes with force flag...${NC}" puts "${BLUE}Running Test 4: Terminate all boxes with force flag${NC}" if {[catch { spawn $gbox_binary box terminate --all --force expect { -re "No boxes to terminate" { puts "${GREEN}✓ Found 'No boxes to terminate' message with force${NC}" } -re "All boxes terminated successfully" { puts "${GREEN}✓ Found success message with force${NC}" } timeout { puts "${RED}✗ Timeout waiting for terminate all with force output${NC}" exit 1 } eof { puts "${RED}✗ Terminate all with force command exited unexpectedly${NC}" exit 1 } } expect { eof { puts "${GREEN}✓ Terminate all with force command completed successfully${NC}" } timeout { puts "${RED}✗ Timeout waiting for terminate all with force completion${NC}" exit 1 } } catch {close} } result]} { puts "${RED}✗ Terminate all with force test failed: $result${NC}" exit 1 } # Test 5: Terminate all boxes with short flags puts "\n${YELLOW}Testing terminate all boxes with short flags...${NC}" puts "${BLUE}Running Test 5: Terminate all boxes with short flags${NC}" if {[catch { spawn $gbox_binary box terminate -a -f expect { -re "No boxes to terminate" { puts "${GREEN}✓ Found 'No boxes to terminate' message with short flags${NC}" } -re "All boxes terminated successfully" { puts "${GREEN}✓ Found success message with short flags${NC}" } timeout { puts "${RED}✗ Timeout waiting for terminate all with short flags output${NC}" exit 1 } eof { puts "${RED}✗ Terminate all with short flags command exited unexpectedly${NC}" exit 1 } } expect { eof { puts "${GREEN}✓ Terminate all with short flags command completed successfully${NC}" } timeout { puts "${RED}✗ Timeout waiting for terminate all with short flags completion${NC}" } } catch {close} } result]} { puts "${RED}✗ Terminate all with short flags test failed: $result${NC}" exit 1 } # Test 6: Terminate all boxes with JSON output puts "\n${YELLOW}Testing terminate all boxes with JSON output...${NC}" puts "${BLUE}Running Test 6: Terminate all boxes with JSON output${NC}" if {[catch { spawn $gbox_binary box terminate --all --output json expect { -re "\{" { puts "${GREEN}✓ Found JSON opening brace${NC}" } timeout { puts "${RED}✗ Timeout waiting for JSON output${NC}" exit 1 } eof { puts "${RED}✗ Terminate all JSON command exited unexpectedly${NC}" exit 1 } } expect { -re "\"status\":" { puts "${GREEN}✓ Found status field in JSON${NC}" } -re "\"message\":" { puts "${GREEN}✓ Found message field in JSON${NC}" } timeout { puts "${RED}✗ Timeout waiting for JSON fields${NC}" exit 1 } } expect { -re "\}" { puts "${GREEN}✓ Found JSON closing brace${NC}" } timeout { puts "${RED}✗ Timeout waiting for JSON closing brace${NC}" exit 1 } } expect { eof { puts "${GREEN}✓ Terminate all JSON command completed successfully${NC}" } timeout { puts "${RED}✗ Timeout waiting for terminate all JSON completion${NC}" exit 1 } } catch {close} } result]} { puts "${RED}✗ Terminate all JSON test failed: $result${NC}" exit 1 } # Test 7: Terminate all boxes with short JSON output flag puts "\n${YELLOW}Testing terminate all boxes with short JSON output flag...${NC}" puts "${BLUE}Running Test 7: Terminate all boxes with short JSON output flag${NC}" if {[catch { spawn $gbox_binary box terminate --all -o json expect { -re "\{" { puts "${GREEN}✓ Found JSON opening brace with short flag${NC}" } timeout { puts "${RED}✗ Timeout waiting for JSON output with short flag${NC}" exit 1 } eof { puts "${RED}✗ Terminate all JSON with short flag command exited unexpectedly${NC}" exit 1 } } expect { eof { puts "${GREEN}✓ Terminate all JSON with short flag command completed successfully${NC}" } timeout { puts "${RED}✗ Timeout waiting for terminate all JSON with short flag completion${NC}" exit 1 } } catch {close} } result]} { puts "${RED}✗ Terminate all JSON with short flag test failed: $result${NC}" exit 1 } # Test 8: Terminate specific box with invalid ID puts "\n${YELLOW}Testing terminate specific box with invalid ID...${NC}" puts "${BLUE}Running Test 8: Terminate specific box with invalid ID${NC}" if {[catch { spawn $gbox_binary box terminate invalid-box-id expect { -re "failed to resolve box ID" { puts "${GREEN}✓ Found expected error for invalid box ID${NC}" } -re "Error:" { puts "${GREEN}✓ Found error message for invalid box ID${NC}" } timeout { puts "${RED}✗ Timeout waiting for invalid box ID error${NC}" exit 1 } eof { puts "${RED}✗ Invalid box ID command exited unexpectedly${NC}" exit 1 } } expect { eof { puts "${GREEN}✓ Invalid box ID error displayed correctly${NC}" } timeout { puts "${RED}✗ Timeout waiting for invalid box ID completion${NC}" exit 1 } } catch {close} } result]} { puts "${RED}✗ Invalid box ID test failed: $result${NC}" exit 1 } # Test 9: Terminate specific box with JSON output puts "\n${YELLOW}Testing terminate specific box with JSON output...${NC}" puts "${BLUE}Running Test 9: Terminate specific box with JSON output${NC}" if {[catch { spawn $gbox_binary box terminate invalid-box-id --output json expect { -re "\{" { puts "${GREEN}✓ Found JSON opening brace for invalid box ID${NC}" } -re "failed to resolve box ID" { puts "${GREEN}✓ Found expected error for invalid box ID in JSON${NC}" } timeout { puts "${RED}✗ Timeout waiting for invalid box ID JSON error${NC}" exit 1 } eof { puts "${RED}✗ Invalid box ID JSON command exited unexpectedly${NC}" exit 1 } } expect { eof { puts "${GREEN}✓ Invalid box ID JSON error displayed correctly${NC}" } timeout { puts "${RED}✗ Timeout waiting for invalid box ID JSON completion${NC}" exit 1 } } catch {close} } result]} { puts "${RED}✗ Invalid box ID JSON test failed: $result${NC}" exit 1 } # Test 10: Conflicting arguments (both --all and box ID) puts "\n${YELLOW}Testing conflicting arguments (both --all and box ID)...${NC}" puts "${BLUE}Running Test 10: Conflicting arguments test${NC}" if {[catch { spawn $gbox_binary box terminate --all some-box-id expect { -re "cannot specify both --all and a box ID" { puts "${GREEN}✓ Found expected error for conflicting arguments${NC}" } timeout { puts "${RED}✗ Timeout waiting for conflicting arguments error${NC}" exit 1 } eof { puts "${RED}✗ Conflicting arguments command exited unexpectedly${NC}" exit 1 } } expect { eof { puts "${GREEN}✓ Conflicting arguments error displayed correctly${NC}" } timeout { puts "${RED}✗ Timeout waiting for conflicting arguments completion${NC}" exit 1 } } catch {close} } result]} { puts "${RED}✗ Conflicting arguments test failed: $result${NC}" exit 1 } # Test 11: Short conflicting arguments (both -a and box ID) puts "\n${YELLOW}Testing short conflicting arguments (both -a and box ID)...${NC}" puts "${BLUE}Running Test 11: Short conflicting arguments test${NC}" if {[catch { spawn $gbox_binary box terminate -a some-box-id expect { -re "cannot specify both --all and a box ID" { puts "${GREEN}✓ Found expected error for short conflicting arguments${NC}" } timeout { puts "${RED}✗ Timeout waiting for short conflicting arguments error${NC}" exit 1 } eof { puts "${RED}✗ Short conflicting arguments command exited unexpectedly${NC}" exit 1 } } expect { eof { puts "${GREEN}✓ Short conflicting arguments error displayed correctly${NC}" } timeout { puts "${RED}✗ Timeout waiting for short conflicting arguments completion${NC}" exit 1 } } catch {close} } result]} { puts "${RED}✗ Short conflicting arguments test failed: $result${NC}" exit 1 } puts "\n${GREEN}All box terminate tests passed successfully!${NC}" exit 0

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/babelcloud/gru-sandbox'

If you have feedback or need assistance with the MCP directory API, please join our Discord server