Files
mc-god/internal/pkg/rcon/rcon_test.go

45 lines
1.1 KiB
Go
Raw Permalink Normal View History

2026-02-12 18:59:15 -08:00
package rcon
import (
"testing"
2026-02-13 14:14:08 -08:00
"github.com/google/go-cmp/cmp"
2026-02-12 18:59:15 -08:00
)
func TestNew(t *testing.T) {
2026-02-13 14:14:08 -08:00
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)
}
2026-02-12 18:59:15 -08:00
}
func TestGetEnvCredentials(t *testing.T) {
// Test that environment variables are properly read
// This test will be skipped in normal execution as environment variables won't be set
t.Log("Testing environment credential reading - placeholder for actual tests")
}
func TestConnectWithTimeout(t *testing.T) {
// This test would require a mock server or actual server connection
t.Log("Testing connection with timeout - placeholder for actual tests")
}