-
Notifications
You must be signed in to change notification settings - Fork 594
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: set proper User-Agent for request made to Kong and Konnect (#5753)
- Loading branch information
1 parent
2825d8e
commit c393bb5
Showing
25 changed files
with
232 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package controlplanes_test | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/google/uuid" | ||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/kong/kubernetes-ingress-controller/v3/internal/konnect/controlplanes" | ||
"github.com/kong/kubernetes-ingress-controller/v3/internal/manager/metadata" | ||
) | ||
|
||
type mockControlPlanesServer struct { | ||
t *testing.T | ||
} | ||
|
||
func newMockControlPlanesServer(t *testing.T) *mockControlPlanesServer { | ||
return &mockControlPlanesServer{ | ||
t: t, | ||
} | ||
} | ||
|
||
func (m *mockControlPlanesServer) ServeHTTP(_ http.ResponseWriter, r *http.Request) { | ||
require.Equal(m.t, metadata.UserAgent(), r.Header.Get("User-Agent")) | ||
} | ||
|
||
func TestControlPlanesClientUserAgent(t *testing.T) { | ||
ts := httptest.NewServer(newMockControlPlanesServer(t)) | ||
t.Cleanup(ts.Close) | ||
|
||
c, err := controlplanes.NewClient(ts.URL) | ||
require.NoError(t, err) | ||
|
||
r, err := c.GetControlPlane(context.Background(), uuid.New()) | ||
require.NoError(t, err) | ||
r.Body.Close() | ||
|
||
r, err = c.DeleteControlPlane(context.Background(), uuid.New()) | ||
require.NoError(t, err) | ||
r.Body.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package controlplanesconfig_test | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/kong/kubernetes-ingress-controller/v3/internal/konnect/controlplanesconfig" | ||
"github.com/kong/kubernetes-ingress-controller/v3/internal/manager/metadata" | ||
) | ||
|
||
type mockControlPlanesConfigServer struct { | ||
t *testing.T | ||
} | ||
|
||
func newMockControlPlanesConfigServer(t *testing.T) *mockControlPlanesConfigServer { | ||
return &mockControlPlanesConfigServer{ | ||
t: t, | ||
} | ||
} | ||
|
||
func (m *mockControlPlanesConfigServer) ServeHTTP(_ http.ResponseWriter, r *http.Request) { | ||
require.Equal(m.t, metadata.UserAgent(), r.Header.Get("User-Agent")) | ||
} | ||
|
||
func TestControlPlanesConfigClientUserAgent(t *testing.T) { | ||
ts := httptest.NewServer(newMockControlPlanesConfigServer(t)) | ||
t.Cleanup(ts.Close) | ||
|
||
c, err := controlplanesconfig.NewClient(ts.URL) | ||
require.NoError(t, err) | ||
|
||
r, err := c.GetNodes(context.Background(), &controlplanesconfig.GetNodesParams{}) | ||
require.NoError(t, err) | ||
r.Body.Close() | ||
|
||
r, err = c.DeleteCoreEntities(context.Background(), "test") | ||
require.NoError(t, err) | ||
r.Body.Close() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package nodes_test | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"net/http/httptest" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/kong/kubernetes-ingress-controller/v3/internal/adminapi" | ||
"github.com/kong/kubernetes-ingress-controller/v3/internal/konnect/nodes" | ||
"github.com/kong/kubernetes-ingress-controller/v3/internal/manager/metadata" | ||
) | ||
|
||
type mockNodesServer struct { | ||
t *testing.T | ||
} | ||
|
||
func newMockNodesServer(t *testing.T) *mockNodesServer { | ||
return &mockNodesServer{ | ||
t: t, | ||
} | ||
} | ||
|
||
func (m *mockNodesServer) ServeHTTP(_ http.ResponseWriter, r *http.Request) { | ||
require.Equal(m.t, metadata.UserAgent(), r.Header.Get("User-Agent")) | ||
} | ||
|
||
func TestNodesClientUserAgent(t *testing.T) { | ||
ts := httptest.NewServer(newMockNodesServer(t)) | ||
t.Cleanup(ts.Close) | ||
|
||
c, err := nodes.NewClient(adminapi.KonnectConfig{Address: ts.URL}) | ||
require.NoError(t, err) | ||
|
||
_, err = c.GetNode(context.Background(), "test-node-id") | ||
require.Error(t, err) | ||
|
||
err = c.DeleteNode(context.Background(), "test-node-id") | ||
require.NoError(t, err) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.