Skip to content

Commit 1f3ab0a

Browse files
committed
merge main, fix conflicts
2 parents 2cb3048 + 09790f5 commit 1f3ab0a

File tree

8 files changed

+290
-497
lines changed

8 files changed

+290
-497
lines changed

.github/workflows/codeql-analysis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ jobs:
5858

5959
# Initializes the CodeQL tools for scanning.
6060
- name: Initialize CodeQL
61-
uses: github/codeql-action/init@8214744c546c1e5c8f03dde8fab3a7353211988d # v3.26.7
61+
uses: github/codeql-action/init@294a9d92911152fe08befb9ec03e240add280cb3 # v3.26.8
6262
with:
6363
languages: ${{ matrix.language }}
6464
build-mode: ${{ matrix.build-mode }}
@@ -70,6 +70,6 @@ jobs:
7070
# queries: security-extended,security-and-quality
7171

7272
- name: Perform CodeQL Analysis
73-
uses: github/codeql-action/analyze@8214744c546c1e5c8f03dde8fab3a7353211988d # v3.26.7
73+
uses: github/codeql-action/analyze@294a9d92911152fe08befb9ec03e240add280cb3 # v3.26.8
7474
with:
7575
category: "/language:${{matrix.language}}"

.github/workflows/f5-cla.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
steps:
2929
- name: Run F5 Contributor License Agreement (CLA) assistant
3030
if: (github.event.comment.body == 'recheck' || github.event.comment.body == 'I have hereby read the F5 CLA and agree to its terms') || github.event_name == 'pull_request_target'
31-
uses: contributor-assistant/github-action@f41946747f85d28e9a738f4f38dbcc74b69c7e0e # v2.5.1
31+
uses: contributor-assistant/github-action@b1522fa982419e79591a92e1267de463a281cdb7 # v2.6.0
3232
with:
3333
# Any pull request targeting the following branch will trigger a CLA check.
3434
branch: "main"

.github/workflows/scorecard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,6 @@ jobs:
5757

5858
# Upload the results to GitHub's code scanning dashboard.
5959
- name: "Upload to code-scanning"
60-
uses: github/codeql-action/upload-sarif@8214744c546c1e5c8f03dde8fab3a7353211988d # v3.26.7
60+
uses: github/codeql-action/upload-sarif@294a9d92911152fe08befb9ec03e240add280cb3 # v3.26.8
6161
with:
6262
sarif_file: results.sarif

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ linters:
3434
- asasalint
3535
- asciicheck
3636
- bidichk
37+
- containedctx
3738
- contextcheck
3839
- copyloopvar
3940
- dupword

client/nginx.go

Lines changed: 164 additions & 312 deletions
Large diffs are not rendered by default.

client/nginx_test.go

Lines changed: 31 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import (
88
"strings"
99
"sync"
1010
"testing"
11-
"time"
1211
)
1312

1413
func TestDetermineUpdates(t *testing.T) {
@@ -581,27 +580,6 @@ func TestClientWithAPIVersion(t *testing.T) {
581580
}
582581
}
583582

584-
func TestClientWithTimeout(t *testing.T) {
585-
t.Parallel()
586-
// Test creating a new client with a supported API version on the client
587-
client, err := NewNginxClient("http://api-url", WithTimeout(1*time.Second))
588-
if err != nil {
589-
t.Fatalf("unexpected error: %v", err)
590-
}
591-
if client == nil {
592-
t.Fatalf("client is nil")
593-
}
594-
595-
// Test creating a new client with an invalid duration
596-
client, err = NewNginxClient("http://api-url", WithTimeout(-1*time.Second))
597-
if err == nil {
598-
t.Fatalf("expected error, but got nil")
599-
}
600-
if client != nil {
601-
t.Fatalf("expected client to be nil, but got %v", client)
602-
}
603-
}
604-
605583
func TestClientWithHTTPClient(t *testing.T) {
606584
t.Parallel()
607585
// Test creating a new client passing a custom HTTP client
@@ -687,21 +665,6 @@ func TestClientWithMaxAPI(t *testing.T) {
687665
}
688666

689667
func TestGetStats_NoStreamEndpoint(t *testing.T) {
690-
tests := []struct {
691-
ctx context.Context
692-
name string
693-
}{
694-
{
695-
ctx: nil,
696-
name: "no context test",
697-
},
698-
{
699-
ctx: context.Background(),
700-
name: "with context test",
701-
},
702-
}
703-
var err error
704-
var client *NginxClient
705668
var writeLock sync.Mutex
706669

707670
t.Parallel()
@@ -712,19 +675,19 @@ func TestGetStats_NoStreamEndpoint(t *testing.T) {
712675
switch {
713676
case r.RequestURI == "/":
714677

715-
_, err = w.Write([]byte(`[4, 5, 6, 7, 8, 9]`))
678+
_, err := w.Write([]byte(`[4, 5, 6, 7, 8, 9]`))
716679
if err != nil {
717680
t.Fatalf("unexpected error: %v", err)
718681
}
719682
case r.RequestURI == "/7/":
720-
_, err = w.Write([]byte(`["nginx","processes","connections","slabs","http","resolvers","ssl"]`))
683+
_, err := w.Write([]byte(`["nginx","processes","connections","slabs","http","resolvers","ssl"]`))
721684
if err != nil {
722685
t.Fatalf("unexpected error: %v", err)
723686
}
724687
case strings.HasPrefix(r.RequestURI, "/7/stream"):
725688
t.Fatal("Stream endpoint should not be called since it does not exist.")
726689
default:
727-
_, err = w.Write([]byte(`{}`))
690+
_, err := w.Write([]byte(`{}`))
728691
if err != nil {
729692
t.Fatalf("unexpected error: %v", err)
730693
}
@@ -733,27 +696,17 @@ func TestGetStats_NoStreamEndpoint(t *testing.T) {
733696
defer ts.Close()
734697

735698
// Test creating a new client with a supported API version on the server
736-
client, err = NewNginxClient(ts.URL, WithAPIVersion(7), WithCheckAPI())
699+
client, err := NewNginxClient(ts.URL, WithAPIVersion(7), WithCheckAPI())
737700
if err != nil {
738701
t.Fatalf("unexpected error: %v", err)
739702
}
740703
if client == nil {
741704
t.Fatalf("client is nil")
742705
}
743706

744-
var stats *Stats
745-
for _, test := range tests {
746-
if test.ctx == nil {
747-
stats, err = client.GetStats()
748-
if err != nil {
749-
t.Fatalf("unexpected error: %v", err)
750-
}
751-
} else {
752-
stats, err = client.GetStatsWithContext(test.ctx)
753-
if err != nil {
754-
t.Fatalf("unexpected error: %v", err)
755-
}
756-
}
707+
stats, err := client.GetStats(context.Background())
708+
if err != nil {
709+
t.Fatalf("unexpected error: %v", err)
757710
}
758711

759712
if !reflect.DeepEqual(stats.StreamServerZones, StreamServerZones{}) {
@@ -771,20 +724,6 @@ func TestGetStats_NoStreamEndpoint(t *testing.T) {
771724
}
772725

773726
func TestGetStats_SSL(t *testing.T) {
774-
tests := []struct {
775-
ctx context.Context
776-
name string
777-
}{
778-
{
779-
ctx: nil,
780-
name: "no context test",
781-
},
782-
{
783-
ctx: context.Background(),
784-
name: "with context test",
785-
},
786-
}
787-
788727
t.Parallel()
789728
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
790729
switch {
@@ -841,41 +780,30 @@ func TestGetStats_SSL(t *testing.T) {
841780
t.Fatalf("client is nil")
842781
}
843782

844-
var stats *Stats
845-
846-
for _, test := range tests {
847-
if test.ctx == nil {
848-
stats, err = client.GetStats()
849-
if err != nil {
850-
t.Fatalf("unexpected error: %v", err)
851-
}
852-
} else {
853-
stats, err = client.GetStatsWithContext(test.ctx)
854-
if err != nil {
855-
t.Fatalf("unexpected error: %v", err)
856-
}
857-
}
783+
stats, err := client.GetStats(context.Background())
784+
if err != nil {
785+
t.Fatalf("unexpected error: %v", err)
786+
}
858787

859-
testStats := SSL{
860-
Handshakes: 79572,
861-
HandshakesFailed: 21025,
862-
SessionReuses: 15762,
863-
NoCommonProtocol: 4,
864-
NoCommonCipher: 2,
865-
HandshakeTimeout: 0,
866-
PeerRejectedCert: 0,
867-
VerifyFailures: VerifyFailures{
868-
NoCert: 0,
869-
ExpiredCert: 2,
870-
RevokedCert: 1,
871-
HostnameMismatch: 2,
872-
Other: 1,
873-
},
874-
}
788+
testStats := SSL{
789+
Handshakes: 79572,
790+
HandshakesFailed: 21025,
791+
SessionReuses: 15762,
792+
NoCommonProtocol: 4,
793+
NoCommonCipher: 2,
794+
HandshakeTimeout: 0,
795+
PeerRejectedCert: 0,
796+
VerifyFailures: VerifyFailures{
797+
NoCert: 0,
798+
ExpiredCert: 2,
799+
RevokedCert: 1,
800+
HostnameMismatch: 2,
801+
Other: 1,
802+
},
803+
}
875804

876-
if !reflect.DeepEqual(stats.SSL, testStats) {
877-
t.Fatalf("SSL stats: expected %v, actual %v", testStats, stats.SSL)
878-
}
805+
if !reflect.DeepEqual(stats.SSL, testStats) {
806+
t.Fatalf("SSL stats: expected %v, actual %v", testStats, stats.SSL)
879807
}
880808
}
881809

@@ -902,7 +830,7 @@ func TestGetMaxAPIVersionServer(t *testing.T) {
902830
t.Fatalf("unexpected error: %v", err)
903831
}
904832

905-
maxVer, err := c.GetMaxAPIVersion()
833+
maxVer, err := c.GetMaxAPIVersion(context.Background())
906834
if err != nil {
907835
t.Fatalf("unexpected error: %v", err)
908836
}
@@ -934,7 +862,7 @@ func TestGetMaxAPIVersionClient(t *testing.T) {
934862
t.Fatalf("unexpected error: %v", err)
935863
}
936864

937-
maxVer, err := c.GetMaxAPIVersion()
865+
maxVer, err := c.GetMaxAPIVersion(context.Background())
938866
if err != nil {
939867
t.Fatalf("unexpected error: %v", err)
940868
}

tests/client_no_stream_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package tests
22

33
import (
4+
"context"
45
"testing"
56

67
"github.com/nginxinc/nginx-plus-go-client/client"
@@ -16,8 +17,8 @@ func TestStatsNoStream(t *testing.T) {
1617
if err != nil {
1718
t.Fatalf("Error connecting to nginx: %v", err)
1819
}
19-
20-
stats, err := c.GetStats()
20+
ctx := context.Background()
21+
stats, err := c.GetStats(ctx)
2122
if err != nil {
2223
t.Errorf("Error getting stats: %v", err)
2324
}

0 commit comments

Comments
 (0)