From a4cfeada63fc9828e5d2f9d8d2b833a387b2ebf6 Mon Sep 17 00:00:00 2001 From: Gisle Aune Date: Sun, 27 May 2018 16:14:04 +0200 Subject: [PATCH] Added function to get client ID, and a test for it --- client.go | 8 ++++++++ client_test.go | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/client.go b/client.go index 6f196a1..ff012d7 100644 --- a/client.go +++ b/client.go @@ -85,6 +85,14 @@ func (client *Client) Context() context.Context { return client.ctx } +// ID gets the unique identifier for the client, which could be used in data structures +func (client *Client) ID() string { + client.mutex.RLock() + defer client.mutex.RUnlock() + + return client.id +} + // Nick gets the nick of the client func (client *Client) Nick() string { client.mutex.RLock() diff --git a/client_test.go b/client_test.go index fdc2fc9..046e4d0 100644 --- a/client_test.go +++ b/client_test.go @@ -8,7 +8,7 @@ import ( "git.aiterp.net/gisle/irc/internal/irctest" ) -func TestClientInteraction(t *testing.T) { +func TestClient(t *testing.T) { client := irc.New(context.Background(), irc.Config{ Nick: "Test", User: "Tester", @@ -16,6 +16,11 @@ func TestClientInteraction(t *testing.T) { Alternatives: []string{"Test2", "Test3", "Test4"}, }) + t.Logf("Client.ID = %#+v", client.ID()) + if client.ID() == "" { + t.Fail() + } + interaction := irctest.Interaction{ Strict: false, Lines: []irctest.InteractionLine{