add: test cases for rcon

This commit is contained in:
2026-02-13 14:14:08 -08:00
parent 7c1697660f
commit db8304bebd
6 changed files with 147 additions and 73 deletions

View File

@@ -44,17 +44,8 @@ The package expects these environment variables to be set:
- `RCON_ADDRESS` - The address of the Minecraft server (e.g., "localhost:25575")
- `RCON_PASSWORD` - The RCON password for authentication
## Methods
## Testing
- `New(address, password)` - Create a new RCON client
- `Execute(command)` - Execute a command on the server
- `SetWeather(weather)` - Set the weather (clear, rain, thunder)
- `SetTime(timeValue)` - Set the time (day, night, noon, midnight, or numeric)
- `SetDifficulty(difficulty)` - Set the difficulty level (peaceful, easy, normal, hard)
- `GetServerInfo()` - Get server version information
- `Close()` - Close the RCON connection
- `HealthCheck()` - Verify the connection is working
- `ExecuteWithTimeout()` - Execute command with timeout
- `ConnectWithTimeout()` - Connect with timeout
- `GetEnvCredentials()` - Get credentials from environment
- `NewFromEnv()` - Create client from environment variables
`rconmock.go` contains a mock rcon server that accepts and logs requests from the user. It can be configured to return errors, or success (empty body strings). It logs the recieved message bodies.
The protocol is described at https://developer.valvesoftware.com/wiki/Source_RCON_Protocol.