add: test cases for rcon
This commit is contained in:
@@ -2,13 +2,34 @@ package rcon
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/google/go-cmp/cmp"
|
||||
)
|
||||
|
||||
func TestNew(t *testing.T) {
|
||||
// This is a placeholder test since we can't actually connect to a server
|
||||
// in a test environment without a real Minecraft server
|
||||
// The actual functionality will be tested with integration tests
|
||||
t.Log("RCON package tests - placeholder for actual tests")
|
||||
serv := MockRCONServer{}
|
||||
done, err := serv.Start()
|
||||
if err != nil {
|
||||
t.Fatalf("failed to start server: %v", err)
|
||||
}
|
||||
|
||||
password := "abc123"
|
||||
client, err := New(serv.Address(), password)
|
||||
if err != nil {
|
||||
t.Fatalf("failed to connect: %v", err)
|
||||
}
|
||||
if _, err = client.Execute("Hello world!"); err != nil {
|
||||
t.Fatalf("failed to run command: %v", err)
|
||||
}
|
||||
|
||||
results := done()
|
||||
want := []string{
|
||||
"abc123",
|
||||
"Hello world!",
|
||||
}
|
||||
if diff := cmp.Diff(want, results.Messages); diff != "" {
|
||||
t.Errorf("Got diff (-want +got):\n%s", diff)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetEnvCredentials(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user