-
Notifications
You must be signed in to change notification settings - Fork 0
feat: build quic addresses #177
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,55 @@ | ||||||||||||||||||||||||||||||||
| package net_test | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| import ( | ||||||||||||||||||||||||||||||||
| "testing" | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| "github.com/stretchr/testify/require" | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| "github.com/getoptimum/optimum-common/pkg/logger" | ||||||||||||||||||||||||||||||||
| "github.com/getoptimum/optimum-common/pkg/net" | ||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||
|
Comment on lines
+3
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Apply the repository’s The lint job fails on this import block, blocking CI. Proposed fix import (
"testing"
"github.com/getoptimum/optimum-common/pkg/logger"
"github.com/getoptimum/optimum-common/pkg/net"
+
"github.com/stretchr/testify/require"
)📝 Committable suggestion
Suggested change
🧰 Tools🪛 GitHub Actions: Lint / golangci _ golangci-lint[error] 5-5: golangci-lint reported formatting issue (gci): File is not properly formatted (gci). 🪛 GitHub Check: golangci / golangci-lint[failure] 5-5: 🤖 Prompt for AI AgentsSources: Linters/SAST tools, Pipeline failures |
||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| func TestBuildAdvertisedQUICAddresses(t *testing.T) { | ||||||||||||||||||||||||||||||||
| l := logger.NewAppSLogger(logger.Debug) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| t.Run("valid payload", func(t *testing.T) { | ||||||||||||||||||||||||||||||||
| res, err := net.BuildAdvertisedQUICAddresses(l, "1.2.3.4", "2001:db8::1", 4001) | ||||||||||||||||||||||||||||||||
| require.NoError(t, err) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| require.Contains(t, res, mustMA(t, "/ip4/1.2.3.4/udp/4001/quic-v1")) | ||||||||||||||||||||||||||||||||
| require.Contains(t, res, mustMA(t, "/ip6/2001:db8::1/udp/4001/quic-v1")) | ||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||
| t.Run("should return err on invalid ipv4", func(t *testing.T) { | ||||||||||||||||||||||||||||||||
| res, err := net.BuildAdvertisedQUICAddresses(l, "not-an-ip", "2001:db8::1", 4001) | ||||||||||||||||||||||||||||||||
| require.Error(t, err) | ||||||||||||||||||||||||||||||||
| require.Empty(t, res) | ||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||
| t.Run("should work with empty ipv6", func(t *testing.T) { | ||||||||||||||||||||||||||||||||
| res, err := net.BuildAdvertisedQUICAddresses(l, "1.2.3.4", "", 4001) | ||||||||||||||||||||||||||||||||
| require.NoError(t, err) | ||||||||||||||||||||||||||||||||
| require.Contains(t, res, mustMA(t, "/ip4/1.2.3.4/udp/4001/quic-v1")) | ||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||
| t.Run("should not fail on invalid ipv6 and still return ipv4", func(t *testing.T) { | ||||||||||||||||||||||||||||||||
| res, err := net.BuildAdvertisedQUICAddresses(l, "1.2.3.4", "not-an-ip", 4001) | ||||||||||||||||||||||||||||||||
| require.NoError(t, err) | ||||||||||||||||||||||||||||||||
| require.Contains(t, res, mustMA(t, "/ip4/1.2.3.4/udp/4001/quic-v1")) | ||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||
| t.Run("should return err on invalid port", func(t *testing.T) { | ||||||||||||||||||||||||||||||||
| res, err := net.BuildAdvertisedQUICAddresses(l, "1.2.3.4", "2001:db8::1", 0) | ||||||||||||||||||||||||||||||||
| require.Error(t, err) | ||||||||||||||||||||||||||||||||
| require.Empty(t, res) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| res, err = net.BuildAdvertisedQUICAddresses(l, "1.2.3.4", "2001:db8::1", 70000) | ||||||||||||||||||||||||||||||||
| require.Error(t, err) | ||||||||||||||||||||||||||||||||
| require.Empty(t, res) | ||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||
| t.Run("should accept boundary ports", func(t *testing.T) { | ||||||||||||||||||||||||||||||||
| res, err := net.BuildAdvertisedQUICAddresses(l, "1.2.3.4", "", 1) | ||||||||||||||||||||||||||||||||
| require.NoError(t, err) | ||||||||||||||||||||||||||||||||
| require.Contains(t, res, mustMA(t, "/ip4/1.2.3.4/udp/1/quic-v1")) | ||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||
| res, err = net.BuildAdvertisedQUICAddresses(l, "1.2.3.4", "", 65535) | ||||||||||||||||||||||||||||||||
| require.NoError(t, err) | ||||||||||||||||||||||||||||||||
| require.Contains(t, res, mustMA(t, "/ip4/1.2.3.4/udp/65535/quic-v1")) | ||||||||||||||||||||||||||||||||
| }) | ||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.