From fb076746720e1efae439fdfa38bf7063423d225f Mon Sep 17 00:00:00 2001 From: gempir Date: Fri, 27 Sep 2024 21:48:46 +0200 Subject: [PATCH 01/10] upgrade all ci to latest version --- .github/workflows/build.yml | 6 +++--- .github/workflows/goveralls.yml | 6 +++--- .github/workflows/lint.yml | 6 +++--- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index aa2f19f..2aa720e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,17 +8,17 @@ jobs: strategy: matrix: - go: [1.16, 1.17] + go: [1.22, 1.23] steps: - name: Set up Go - uses: actions/setup-go@v1 + uses: actions/setup-go@v5 with: go-version: ${{ matrix.go }} id: go - name: Check out code into the Go module directory - uses: actions/checkout@v1 + uses: actions/checkout@v4 - name: Get dependencies run: | diff --git a/.github/workflows/goveralls.yml b/.github/workflows/goveralls.yml index ffc6a51..0e1ad6b 100644 --- a/.github/workflows/goveralls.yml +++ b/.github/workflows/goveralls.yml @@ -8,15 +8,15 @@ jobs: strategy: matrix: - go: [1.16, 1.17] + go: [1.22, 1.23] steps: - name: Set up Go - uses: actions/setup-go@v1 + uses: actions/setup-go@v5 with: go-version: ${{ matrix.go }} - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - run: go test -coverprofile=coverage.out - uses: shogo82148/actions-goveralls@v1 with: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 171f767..b08aa83 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -6,13 +6,13 @@ jobs: name: runner / golangci-lint (pre-build docker image) runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2.3.4 + - uses: actions/checkout@v4 with: fetch-depth: 0 - name: golangci-lint - uses: golangci/golangci-lint-action@v2.3.0 + uses: golangci/golangci-lint-action@v6 with: - version: v1.42 + version: v1.61 args: --new-from-rev=e0a5614e47d349897~0 From 1cd59dd36e1509513591378ca16f537613da8966 Mon Sep 17 00:00:00 2001 From: gempir Date: Fri, 27 Sep 2024 21:55:05 +0200 Subject: [PATCH 02/10] address linter --- client.go | 2 +- client_test.go | 24 +++++++++++++++++------- 2 files changed, 18 insertions(+), 8 deletions(-) diff --git a/client.go b/client.go index 9e0b784..e6d8227 100644 --- a/client.go +++ b/client.go @@ -595,7 +595,7 @@ func (c *Client) Say(channel, text string) { } // Reply to a message previously sent in the same channel using the twitch reply feature -func (c *Client) Reply(channel, parentMsgId string, text string) { +func (c *Client) Reply(channel, parentMsgId, text string) { channel = strings.ToLower(channel) c.send(fmt.Sprintf("@reply-parent-msg-id=%s PRIVMSG #%s :%s", parentMsgId, channel, text)) diff --git a/client_test.go b/client_test.go index 3d24385..b247b1e 100644 --- a/client_test.go +++ b/client_test.go @@ -1080,7 +1080,7 @@ func TestCanSayMessage(t *testing.T) { func TestCanReplyMessage(t *testing.T) { t.Parallel() testMessage := "Do not go gentle into that good night." - testParentMessageId := "b34ccfc7-4977-403a-8a94-33c6bac34fb8" + testParentMessageID := "b34ccfc7-4977-403a-8a94-33c6bac34fb8" waitEnd := make(chan struct{}) var received string @@ -1095,10 +1095,15 @@ func TestCanReplyMessage(t *testing.T) { client := newTestClient(host) client.OnConnect(func() { - client.Reply("gempir", testParentMessageId, testMessage) + client.Reply("gempir", testParentMessageID, testMessage) }) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() // wait for server to receive message select { @@ -1107,7 +1112,7 @@ func TestCanReplyMessage(t *testing.T) { t.Fatal("no privmsg received") } - assertStringsEqual(t, "@reply-parent-msg-id="+testParentMessageId+" PRIVMSG #gempir :"+testMessage, received) + assertStringsEqual(t, "@reply-parent-msg-id="+testParentMessageID+" PRIVMSG #gempir :"+testMessage, received) } func TestCanJoinChannel(t *testing.T) { @@ -1126,7 +1131,12 @@ func TestCanJoinChannel(t *testing.T) { client.Join("gempiR") - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() // wait for server to receive message select { @@ -2158,12 +2168,12 @@ func TestCapabilities(t *testing.T) { { "Default Capabilities (not modifying)", nil, - "CAP REQ :" + strings.Join([]string{TagsCapability, CommandsCapability}, " "), + "CAP REQ :" + TagsCapability + " " + CommandsCapability, }, { "Modified Capabilities", []string{CommandsCapability, MembershipCapability}, - "CAP REQ :" + strings.Join([]string{CommandsCapability, MembershipCapability}, " "), + "CAP REQ :" + CommandsCapability + " " + MembershipCapability, }, } From 835fa9aa38c98addb3540c08019c15c7b484f6be Mon Sep 17 00:00:00 2001 From: gempir Date: Fri, 27 Sep 2024 22:03:31 +0200 Subject: [PATCH 03/10] more lint errors --- client.go | 4 +- client_test.go | 283 +++++++++++++++++++++++++++++++++------ cmd/pingpong/pingpong.go | 1 + 3 files changed, 245 insertions(+), 43 deletions(-) diff --git a/client.go b/client.go index e6d8227..46f8454 100644 --- a/client.go +++ b/client.go @@ -595,10 +595,10 @@ func (c *Client) Say(channel, text string) { } // Reply to a message previously sent in the same channel using the twitch reply feature -func (c *Client) Reply(channel, parentMsgId, text string) { +func (c *Client) Reply(channel, parentMsgID, text string) { channel = strings.ToLower(channel) - c.send(fmt.Sprintf("@reply-parent-msg-id=%s PRIVMSG #%s :%s", parentMsgId, channel, text)) + c.send(fmt.Sprintf("@reply-parent-msg-id=%s PRIVMSG #%s :%s", parentMsgID, channel, text)) } // Join enter a twitch channel to read more messages. diff --git a/client_test.go b/client_test.go index b247b1e..898f48d 100644 --- a/client_test.go +++ b/client_test.go @@ -283,7 +283,12 @@ func TestCanConnectAndAuthenticateWithoutTLS(t *testing.T) { client.TLS = false client.IrcAddress = host client.PongTimeout = time.Second * 30 - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() select { case <-wait: @@ -312,7 +317,12 @@ func TestCanChangeOauthToken(t *testing.T) { client.TLS = false client.IrcAddress = host client.SetIRCToken(oauthCode) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() select { case <-wait: @@ -342,7 +352,12 @@ func TestCanAddSetupCmd(t *testing.T) { client.TLS = false client.IrcAddress = host client.SetupCmd = setupCmd - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() select { case <-wait: @@ -491,7 +506,12 @@ func TestCanDisconnect(t *testing.T) { close(wait) }) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() // wait for server to start select { @@ -530,7 +550,12 @@ func TestCanReceivePRIVMSGMessage(t *testing.T) { close(wait) }) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() // wait for server to start select { @@ -558,7 +583,12 @@ func TestCanReceiveWHISPERMessage(t *testing.T) { close(wait) }) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() // wait for server to start select { @@ -586,7 +616,12 @@ func TestCanReceiveCLEARCHATMessage(t *testing.T) { close(wait) }) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() // wait for server to start select { @@ -614,7 +649,12 @@ func TestCanReceiveCLEARMSGMessage(t *testing.T) { close(wait) }) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() // wait for server to start select { @@ -642,7 +682,12 @@ func TestCanReceiveROOMSTATEMessage(t *testing.T) { close(wait) }) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() // wait for server to start select { @@ -670,7 +715,12 @@ func TestCanReceiveUSERNOTICEMessage(t *testing.T) { close(wait) }) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() select { case <-wait: @@ -696,7 +746,12 @@ func TestCanReceiveUSERNOTICEMessageResub(t *testing.T) { close(wait) }) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() select { case <-wait: @@ -723,7 +778,12 @@ func checkNoticeMessage(t *testing.T, testMessage string, requirements map[strin close(wait) }) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() select { case <-wait: @@ -773,7 +833,12 @@ func TestCanReceiveUSERStateMessage(t *testing.T) { close(wait) }) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() select { case <-wait: @@ -801,7 +866,12 @@ func TestCanReceiveGlobalUserStateMessage(t *testing.T) { }) //nolint - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() select { case <-wait: @@ -827,7 +897,12 @@ func TestCanReceiveJOINMessage(t *testing.T) { close(wait) }) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() // wait for server to start select { @@ -867,7 +942,12 @@ func TestReceiveJOINMessageWithSelfJOIN(t *testing.T) { wg.Done() }) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() // hack with ctx makes it possible to use it in select statement below ctx, cancel := context.WithCancel(context.Background()) @@ -907,7 +987,12 @@ func TestCanReceivePARTMessage(t *testing.T) { close(wait) }) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() // wait for server to start select { @@ -947,7 +1032,12 @@ func TestReceivePARTMessageWithSelfPART(t *testing.T) { wg.Done() }) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() // hack with ctx makes it possible to use it in select statement below ctx, cancel := context.WithCancel(context.Background()) @@ -989,7 +1079,12 @@ func TestCanReceiveUNSETMessage(t *testing.T) { } }) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() select { case <-wait: @@ -1023,7 +1118,12 @@ func TestCanHandleRECONNECTMessage(t *testing.T) { received = msg }) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() // wait for server to start select { @@ -1065,7 +1165,12 @@ func TestCanSayMessage(t *testing.T) { client.Say("gempir", testMessage) }) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() // wait for server to receive message select { @@ -1161,7 +1266,12 @@ func TestCanJoinChannelAfterConnection(t *testing.T) { }) client := newTestClient(host) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() // wait for the connection to go active for !client.connActive.get() { @@ -1199,7 +1309,12 @@ func TestCanRespectDefaultJoinRateLimits(t *testing.T) { client := newTestClient(host) client.PongTimeout = time.Second * 30 client.SetJoinRateLimiter(CreateDefaultRateLimiter()) - go client.Connect() //nolint + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() //nolint // wait for the connection to go active for !client.connActive.get() { @@ -1244,7 +1359,12 @@ func TestCanRespectBulkDefaultJoinRateLimits(t *testing.T) { client := newTestClient(host) client.PongTimeout = time.Second * 60 client.SetJoinRateLimiter(CreateDefaultRateLimiter()) - go client.Connect() //nolint + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() //nolint // wait for the connection to go active for !client.connActive.get() { @@ -1293,7 +1413,12 @@ func TestCanRespectVerifiedJoinRateLimits(t *testing.T) { client := newTestClient(host) client.PongTimeout = time.Second * 30 client.SetJoinRateLimiter(CreateVerifiedRateLimiter()) - go client.Connect() //nolint + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() //nolint // wait for the connection to go active for !client.connActive.get() { @@ -1335,7 +1460,12 @@ func TestCanIgnoreJoinRateLimits(t *testing.T) { client := newTestClient(host) client.PongTimeout = time.Second * 30 client.SetJoinRateLimiter(CreateUnlimitedRateLimiter()) - go client.Connect() //nolint + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() //nolint // wait for the connection to go active for !client.connActive.get() { @@ -1373,7 +1503,12 @@ func TestCanDepartChannel(t *testing.T) { }) client := newTestClient(host) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() // wait for the connection to go active for !client.connActive.get() { @@ -1434,7 +1569,12 @@ func TestCanGetUserlist(t *testing.T) { } }) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() // wait for the connection to go active for !client.connActive.get() { @@ -1472,7 +1612,12 @@ func TestDepartNegatesJoinIfNotConnected(t *testing.T) { client.Join("gempir") client.Depart("gempir") - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() // wait for the connection to go active for !client.connActive.get() { @@ -1504,7 +1649,12 @@ func TestCanRespondToPING1(t *testing.T) { client := newTestClient(host) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() // wait for server to receive message select { @@ -1529,7 +1679,12 @@ func TestCanRespondToPING2(t *testing.T) { client := newTestClient(host) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() // wait for server to receive message select { @@ -1552,7 +1707,12 @@ func TestCanAttachToPingMessageCallback(t *testing.T) { close(wait) }) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() // wait for server to receive message select { @@ -1577,7 +1737,12 @@ func TestCanPong(t *testing.T) { client := newTestClient(host) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() // wait for server to receive message select { @@ -1700,7 +1865,12 @@ func TestLocalSendingPingsReceivedPong(t *testing.T) { client := newTestClient(host) client.IdlePingInterval = idlePingInterval - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() select { case <-wait: @@ -1728,7 +1898,12 @@ func TestLocalCanReconnectAfterNoPongResponse(t *testing.T) { client.IdlePingInterval = idlePingInterval client.PongTimeout = pongTimeout - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() select { case <-wait: @@ -1770,7 +1945,8 @@ func TestLocalSendingPingsReceivedPongAlsoDisconnect(t *testing.T) { }, func(message string) { if message == pingMessage { // Send an emulated pong - fmt.Fprintf(conn, formatPong(strings.Split(message, " :")[1])+"\r\n") + pongMessage := formatPong(strings.Split(message, " :")[1]) + fmt.Fprintf(conn, "%s\r\n", pongMessage) conn.Close() wait <- true } @@ -1778,7 +1954,12 @@ func TestLocalSendingPingsReceivedPongAlsoDisconnect(t *testing.T) { client := newTestClient(host) client.IdlePingInterval = idlePingInterval - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() select { case <-wait: @@ -1824,7 +2005,12 @@ func TestPinger(t *testing.T) { pingpongMutex.Unlock() }) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() select { case <-wait: @@ -1907,7 +2093,12 @@ func TestLatency(t *testing.T) { client := newTestClient(host) client.IdlePingInterval = idlePingInterval - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() select { case <-wait: @@ -1964,7 +2155,12 @@ func TestCanAttachToPongMessageCallback(t *testing.T) { close(wait) }) - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() select { case <-wait: @@ -2146,7 +2342,12 @@ func TestRejoinOnReconnect(t *testing.T) { waitEnd = make(chan struct{}) // Manually reconnect - go client.Connect() + go func() { + err := client.Connect() + if err != nil { + t.Error(err) + } + }() select { case <-waitEnd: diff --git a/cmd/pingpong/pingpong.go b/cmd/pingpong/pingpong.go index a486821..fffd307 100644 --- a/cmd/pingpong/pingpong.go +++ b/cmd/pingpong/pingpong.go @@ -4,6 +4,7 @@ import ( "log" "strings" + //nolint:depguard twitch "github.com/gempir/go-twitch-irc/v4" ) From 911e8e75ce32e4a451b3d86566ba72d90fdc8857 Mon Sep 17 00:00:00 2001 From: gempir Date: Fri, 27 Sep 2024 22:09:17 +0200 Subject: [PATCH 04/10] lint --- client_test.go | 57 +++++++++++++++++++++++++++++++--------- cmd/pingpong/pingpong.go | 2 +- 2 files changed, 45 insertions(+), 14 deletions(-) diff --git a/client_test.go b/client_test.go index 898f48d..414de38 100644 --- a/client_test.go +++ b/client_test.go @@ -393,7 +393,12 @@ func TestCanConnectAndAuthenticate(t *testing.T) { client := newTestClient(host) client.PongTimeout = time.Second * 30 connectAndEnsureGoodDisconnect(t, client) - defer client.Disconnect() + defer func() { + err := client.Disconnect() + if err != nil { + t.Error(err) + } + }() select { case <-wait: @@ -1792,7 +1797,10 @@ func TestCanConnectToTwitch(t *testing.T) { client := NewClient("justinfan123123", "oauth:123123132") client.OnConnect(func() { - client.Disconnect() + err := client.Disconnect() + if err != nil { + t.Error(err) + } }) err := client.Connect() @@ -1806,7 +1814,10 @@ func TestCanConnectToTwitchWithoutTLS(t *testing.T) { wait := make(chan struct{}) client.OnConnect(func() { - client.Disconnect() + err := client.Disconnect() + if err != nil { + t.Error(err) + } }) go func() { @@ -1858,7 +1869,8 @@ func TestLocalSendingPingsReceivedPong(t *testing.T) { }, func(message string) { if message == pingMessage { // Send an emulated pong - fmt.Fprintf(conn, formatPong(strings.Split(message, " :")[1])+"\r\n") + pongMessage := formatPong(strings.Split(message, " :")[1]) + fmt.Fprintf(conn, "%s\r\n", pongMessage) wait <- true } }) @@ -1878,7 +1890,10 @@ func TestLocalSendingPingsReceivedPong(t *testing.T) { t.Fatal("Did not establish a connection") } - client.Disconnect() + err := client.Disconnect() + if err != nil { + t.Error(err) + } } func TestLocalCanReconnectAfterNoPongResponse(t *testing.T) { @@ -1967,7 +1982,10 @@ func TestLocalSendingPingsReceivedPongAlsoDisconnect(t *testing.T) { t.Fatal("Did not establish a connection") } - client.Disconnect() + err := client.Disconnect() + if err != nil { + t.Error(err) + } } func TestPinger(t *testing.T) { @@ -1987,7 +2005,8 @@ func TestPinger(t *testing.T) { }, func(message string) { if message == pingMessage { // Send an emulated pong - fmt.Fprintf(conn, formatPong(strings.Split(message, " :")[1])+"\r\n") + pongMessage := formatPong(strings.Split(message, " :")[1]) + fmt.Fprintf(conn, "%s\r\n", pongMessage) wait <- true } }) @@ -2041,7 +2060,10 @@ func TestPinger(t *testing.T) { t.Fatal("Did not receive a pong") } - client.Disconnect() + err := client.Disconnect() + if err != nil { + t.Error(err) + } } func TestLatencySendPingsFalse(t *testing.T) { @@ -2087,7 +2109,8 @@ func TestLatency(t *testing.T) { // Send an emulated pong <-time.After(expectedLatency) wait <- true - fmt.Fprintf(conn, formatPong(strings.Split(message, " :")[1])+"\r\n") + pongMessage := formatPong(strings.Split(message, " :")[1]) + fmt.Fprintf(conn, "%s\r\n", pongMessage) } }) client := newTestClient(host) @@ -2131,10 +2154,12 @@ func TestLatency(t *testing.T) { if latencyDiff > toleranceLatency { t.Fatalf("Latency %s should be within 3ms of %s", returnedLatency, expectedLatency) } - } - client.Disconnect() + err = client.Disconnect() + if err != nil { + t.Error(err) + } } func TestCanAttachToPongMessageCallback(t *testing.T) { @@ -2168,7 +2193,10 @@ func TestCanAttachToPongMessageCallback(t *testing.T) { t.Fatal("Did not establish a connection") } - client.Disconnect() + err := client.Disconnect() + if err != nil { + t.Error(err) + } assertStringsEqual(t, "go-twitch-irc", received) } @@ -2335,7 +2363,10 @@ func TestRejoinOnReconnect(t *testing.T) { receivedMsg = "" // Manually disconnect - client.Disconnect() + err := client.Disconnect() + if err != nil { + t.Error(err) + } <-clientDisconnected diff --git a/cmd/pingpong/pingpong.go b/cmd/pingpong/pingpong.go index fffd307..9283502 100644 --- a/cmd/pingpong/pingpong.go +++ b/cmd/pingpong/pingpong.go @@ -4,7 +4,7 @@ import ( "log" "strings" - //nolint:depguard + //nolint:depguard don't understand the linter error twitch "github.com/gempir/go-twitch-irc/v4" ) From 6c10fa977e3d3c0ea3f036759122a837404c7c1a Mon Sep 17 00:00:00 2001 From: gempir Date: Fri, 27 Sep 2024 22:11:42 +0200 Subject: [PATCH 05/10] use oldstable and stable --- .github/workflows/build.yml | 2 +- .github/workflows/goveralls.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 2aa720e..3cb0e83 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: - go: [1.22, 1.23] + go: [stable, oldstable] steps: - name: Set up Go diff --git a/.github/workflows/goveralls.yml b/.github/workflows/goveralls.yml index 0e1ad6b..ef3352b 100644 --- a/.github/workflows/goveralls.yml +++ b/.github/workflows/goveralls.yml @@ -8,7 +8,7 @@ jobs: strategy: matrix: - go: [1.22, 1.23] + go: [stable, oldstable] steps: - name: Set up Go From 4a5e0170a0b9510f21a4d30d4484c532d93dfac7 Mon Sep 17 00:00:00 2001 From: gempir Date: Fri, 27 Sep 2024 22:14:05 +0200 Subject: [PATCH 06/10] we dont use deps, why use depguard --- .golangci.yml | 1 - cmd/pingpong/pingpong.go | 1 - 2 files changed, 2 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 98000ea..4582263 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -28,7 +28,6 @@ linters: enable: - bodyclose - deadcode - - depguard - dogsled # - dupl - errcheck diff --git a/cmd/pingpong/pingpong.go b/cmd/pingpong/pingpong.go index 9283502..a486821 100644 --- a/cmd/pingpong/pingpong.go +++ b/cmd/pingpong/pingpong.go @@ -4,7 +4,6 @@ import ( "log" "strings" - //nolint:depguard don't understand the linter error twitch "github.com/gempir/go-twitch-irc/v4" ) From 18c1f33fe3da7c521294cd5d1c1942949c6117c7 Mon Sep 17 00:00:00 2001 From: gempir Date: Fri, 27 Sep 2024 22:18:45 +0200 Subject: [PATCH 07/10] get rid of dead linters --- .golangci.yml | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 4582263..bce8f73 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -1,12 +1,8 @@ linters-settings: govet: check-shadowing: true - golint: - min-confidence: 0 gocyclo: min-complexity: 15 - maligned: - suggest-new: true goconst: min-len: 2 min-occurrences: 4 @@ -27,9 +23,7 @@ linters: disable-all: true enable: - bodyclose - - deadcode - dogsled - # - dupl - errcheck - funlen - goconst @@ -37,27 +31,18 @@ linters: - gocyclo - gofmt - goimports - - golint - gosec - gosimple - govet - ineffassign - - interfacer - # - lll - # - misspell - - scopelint - staticcheck - - structcheck - stylecheck - typecheck - unconvert - unparam - # - unused - - varcheck + - unused - whitespace - gocognit - # - godox - # - maligned - prealloc # don't enable: From 3ee142c3e4038d09c56a4baf48351c45217307a8 Mon Sep 17 00:00:00 2001 From: gempir Date: Fri, 27 Sep 2024 22:20:39 +0200 Subject: [PATCH 08/10] fix test --- client_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/client_test.go b/client_test.go index 414de38..b1527ba 100644 --- a/client_test.go +++ b/client_test.go @@ -395,8 +395,8 @@ func TestCanConnectAndAuthenticate(t *testing.T) { connectAndEnsureGoodDisconnect(t, client) defer func() { err := client.Disconnect() - if err != nil { - t.Error(err) + if err == nil { + t.Error(err, "connection should not be open") } }() From 9bf3bb3d7c56a1b2c458e52c12fa45cd12838f38 Mon Sep 17 00:00:00 2001 From: gempir Date: Fri, 27 Sep 2024 22:33:17 +0200 Subject: [PATCH 09/10] revert to previous logic --- client_test.go | 266 ++++++++++++++++++------------------------------- 1 file changed, 97 insertions(+), 169 deletions(-) diff --git a/client_test.go b/client_test.go index b1527ba..8f30940 100644 --- a/client_test.go +++ b/client_test.go @@ -284,10 +284,9 @@ func TestCanConnectAndAuthenticateWithoutTLS(t *testing.T) { client.IrcAddress = host client.PongTimeout = time.Second * 30 go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() select { @@ -318,10 +317,9 @@ func TestCanChangeOauthToken(t *testing.T) { client.IrcAddress = host client.SetIRCToken(oauthCode) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() select { @@ -353,10 +351,7 @@ func TestCanAddSetupCmd(t *testing.T) { client.IrcAddress = host client.SetupCmd = setupCmd go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + _ = client.Connect() }() select { @@ -512,10 +507,7 @@ func TestCanDisconnect(t *testing.T) { }) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + _ = client.Connect() }() // wait for server to start @@ -556,10 +548,7 @@ func TestCanReceivePRIVMSGMessage(t *testing.T) { }) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + _ = client.Connect() }() // wait for server to start @@ -589,10 +578,9 @@ func TestCanReceiveWHISPERMessage(t *testing.T) { }) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() // wait for server to start @@ -622,10 +610,9 @@ func TestCanReceiveCLEARCHATMessage(t *testing.T) { }) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() // wait for server to start @@ -655,10 +642,9 @@ func TestCanReceiveCLEARMSGMessage(t *testing.T) { }) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() // wait for server to start @@ -688,10 +674,7 @@ func TestCanReceiveROOMSTATEMessage(t *testing.T) { }) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + _ = client.Connect() }() // wait for server to start @@ -721,10 +704,9 @@ func TestCanReceiveUSERNOTICEMessage(t *testing.T) { }) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() select { @@ -752,10 +734,9 @@ func TestCanReceiveUSERNOTICEMessageResub(t *testing.T) { }) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() select { @@ -784,10 +765,9 @@ func checkNoticeMessage(t *testing.T, testMessage string, requirements map[strin }) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() select { @@ -839,10 +819,9 @@ func TestCanReceiveUSERStateMessage(t *testing.T) { }) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() select { @@ -872,10 +851,9 @@ func TestCanReceiveGlobalUserStateMessage(t *testing.T) { //nolint go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() select { @@ -903,10 +881,9 @@ func TestCanReceiveJOINMessage(t *testing.T) { }) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() // wait for server to start @@ -948,10 +925,9 @@ func TestReceiveJOINMessageWithSelfJOIN(t *testing.T) { }) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() // hack with ctx makes it possible to use it in select statement below @@ -993,10 +969,7 @@ func TestCanReceivePARTMessage(t *testing.T) { }) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + _ = client.Connect() }() // wait for server to start @@ -1038,10 +1011,9 @@ func TestReceivePARTMessageWithSelfPART(t *testing.T) { }) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() // hack with ctx makes it possible to use it in select statement below @@ -1085,10 +1057,9 @@ func TestCanReceiveUNSETMessage(t *testing.T) { }) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() select { @@ -1124,10 +1095,7 @@ func TestCanHandleRECONNECTMessage(t *testing.T) { }) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + _ = client.Connect() }() // wait for server to start @@ -1171,10 +1139,7 @@ func TestCanSayMessage(t *testing.T) { }) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + _ = client.Connect() }() // wait for server to receive message @@ -1209,10 +1174,7 @@ func TestCanReplyMessage(t *testing.T) { }) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + _ = client.Connect() }() // wait for server to receive message @@ -1242,10 +1204,9 @@ func TestCanJoinChannel(t *testing.T) { client.Join("gempiR") go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() // wait for server to receive message @@ -1272,10 +1233,9 @@ func TestCanJoinChannelAfterConnection(t *testing.T) { client := newTestClient(host) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() // wait for the connection to go active @@ -1315,10 +1275,9 @@ func TestCanRespectDefaultJoinRateLimits(t *testing.T) { client.PongTimeout = time.Second * 30 client.SetJoinRateLimiter(CreateDefaultRateLimiter()) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() //nolint // wait for the connection to go active @@ -1365,10 +1324,9 @@ func TestCanRespectBulkDefaultJoinRateLimits(t *testing.T) { client.PongTimeout = time.Second * 60 client.SetJoinRateLimiter(CreateDefaultRateLimiter()) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() //nolint // wait for the connection to go active @@ -1419,10 +1377,9 @@ func TestCanRespectVerifiedJoinRateLimits(t *testing.T) { client.PongTimeout = time.Second * 30 client.SetJoinRateLimiter(CreateVerifiedRateLimiter()) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() //nolint // wait for the connection to go active @@ -1466,10 +1423,9 @@ func TestCanIgnoreJoinRateLimits(t *testing.T) { client.PongTimeout = time.Second * 30 client.SetJoinRateLimiter(CreateUnlimitedRateLimiter()) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() //nolint // wait for the connection to go active @@ -1509,10 +1465,9 @@ func TestCanDepartChannel(t *testing.T) { client := newTestClient(host) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() // wait for the connection to go active @@ -1575,10 +1530,9 @@ func TestCanGetUserlist(t *testing.T) { }) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() // wait for the connection to go active @@ -1618,10 +1572,7 @@ func TestDepartNegatesJoinIfNotConnected(t *testing.T) { client.Depart("gempir") go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + _ = client.Connect() }() // wait for the connection to go active @@ -1655,10 +1606,9 @@ func TestCanRespondToPING1(t *testing.T) { client := newTestClient(host) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() // wait for server to receive message @@ -1685,10 +1635,9 @@ func TestCanRespondToPING2(t *testing.T) { client := newTestClient(host) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() // wait for server to receive message @@ -1713,10 +1662,9 @@ func TestCanAttachToPingMessageCallback(t *testing.T) { }) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() // wait for server to receive message @@ -1743,10 +1691,9 @@ func TestCanPong(t *testing.T) { client := newTestClient(host) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() // wait for server to receive message @@ -1878,10 +1825,7 @@ func TestLocalSendingPingsReceivedPong(t *testing.T) { client.IdlePingInterval = idlePingInterval go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + _ = client.Connect() }() select { @@ -1914,10 +1858,7 @@ func TestLocalCanReconnectAfterNoPongResponse(t *testing.T) { client.PongTimeout = pongTimeout go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + _ = client.Connect() }() select { @@ -1970,10 +1911,7 @@ func TestLocalSendingPingsReceivedPongAlsoDisconnect(t *testing.T) { client.IdlePingInterval = idlePingInterval go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + _ = client.Connect() }() select { @@ -2025,10 +1963,7 @@ func TestPinger(t *testing.T) { }) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + _ = client.Connect() }() select { @@ -2117,10 +2052,7 @@ func TestLatency(t *testing.T) { client.IdlePingInterval = idlePingInterval go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + _ = client.Connect() }() select { @@ -2152,7 +2084,7 @@ func TestLatency(t *testing.T) { }() if latencyDiff > toleranceLatency { - t.Fatalf("Latency %s should be within 3ms of %s", returnedLatency, expectedLatency) + t.Fatalf("Latency %s should be within 5ms of %s", returnedLatency, expectedLatency) } } @@ -2181,10 +2113,7 @@ func TestCanAttachToPongMessageCallback(t *testing.T) { }) go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + _ = client.Connect() }() select { @@ -2374,10 +2303,9 @@ func TestRejoinOnReconnect(t *testing.T) { // Manually reconnect go func() { - err := client.Connect() - if err != nil { - t.Error(err) - } + go func() { + _ = client.Connect() + }() }() select { From 615842ec52dd40d9ea0ace41afb6f03b92009794 Mon Sep 17 00:00:00 2001 From: gempir Date: Fri, 27 Sep 2024 22:36:08 +0200 Subject: [PATCH 10/10] do not run double --- .github/workflows/build.yml | 2 +- .github/workflows/goveralls.yml | 2 +- .github/workflows/lint.yml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3cb0e83..2599551 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,5 +1,5 @@ name: Build -on: [push, pull_request] +on: [pull_request] jobs: build: diff --git a/.github/workflows/goveralls.yml b/.github/workflows/goveralls.yml index ef3352b..466d006 100644 --- a/.github/workflows/goveralls.yml +++ b/.github/workflows/goveralls.yml @@ -1,5 +1,5 @@ name: Goveralls -on: [push, pull_request] +on: [pull_request] jobs: goveralls: diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index b08aa83..8240e46 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -1,5 +1,5 @@ name: Go (Lint) -on: [push, pull_request] +on: [pull_request] jobs: golangci-lint: