45 lines
1.1 KiB
Go
45 lines
1.1 KiB
Go
package rcon
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
)
|
|
|
|
func TestNew(t *testing.T) {
|
|
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) {
|
|
// 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")
|
|
}
|