From 4fa3eb505f6b25691c890c670e322b70585f72b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20=C5=9Awi=C4=99cki?= Date: Sun, 19 Nov 2023 19:25:49 +0100 Subject: [PATCH] Use random port in tests --- pkg/cmd/cinode_web_proxy/root.go | 4 ++-- pkg/cmd/cinode_web_proxy/root_test.go | 1 + pkg/cmd/public_node/root.go | 4 ++-- pkg/cmd/public_node/root_test.go | 2 ++ 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/pkg/cmd/cinode_web_proxy/root.go b/pkg/cmd/cinode_web_proxy/root.go index be555a4..c3d4658 100644 --- a/pkg/cmd/cinode_web_proxy/root.go +++ b/pkg/cmd/cinode_web_proxy/root.go @@ -164,8 +164,8 @@ func getConfig() (*config, error) { cfg.port = 8080 } else { portNum, err := strconv.Atoi(port) - if err == nil && (portNum < 1 || portNum > 65535) { - err = fmt.Errorf("not in range 1..65535") + if err == nil && (portNum < 0 || portNum > 65535) { + err = fmt.Errorf("not in range 0..65535") } if err != nil { return nil, fmt.Errorf("invalid listen port %s: %w", port, err) diff --git a/pkg/cmd/cinode_web_proxy/root_test.go b/pkg/cmd/cinode_web_proxy/root_test.go index 5e2bb3e..f55f8ba 100644 --- a/pkg/cmd/cinode_web_proxy/root_test.go +++ b/pkg/cmd/cinode_web_proxy/root_test.go @@ -289,6 +289,7 @@ func TestExecute(t *testing.T) { ep := testblobs.DynamicLink.Entrypoint() t.Setenv("CINODE_ENTRYPOINT", ep.String()) + t.Setenv("CINODE_LISTEN_PORT", "0") ctx, cancel := context.WithCancel(context.Background()) go func() { time.Sleep(10 * time.Millisecond) diff --git a/pkg/cmd/public_node/root.go b/pkg/cmd/public_node/root.go index 0f19d82..e326a73 100644 --- a/pkg/cmd/public_node/root.go +++ b/pkg/cmd/public_node/root.go @@ -174,8 +174,8 @@ func getConfig() (*config, error) { cfg.port = 8080 } else { portNum, err := strconv.Atoi(port) - if err == nil && (portNum < 1 || portNum > 65535) { - err = fmt.Errorf("not in range 1..65535") + if err == nil && (portNum < 0 || portNum > 65535) { + err = fmt.Errorf("not in range 0..65535") } if err != nil { return nil, fmt.Errorf("invalid listen port %s: %w", port, err) diff --git a/pkg/cmd/public_node/root_test.go b/pkg/cmd/public_node/root_test.go index 3e7f4df..105a0b2 100644 --- a/pkg/cmd/public_node/root_test.go +++ b/pkg/cmd/public_node/root_test.go @@ -189,6 +189,8 @@ func TestExecuteWithConfig(t *testing.T) { func TestExecute(t *testing.T) { t.Run("valid configuration", func(t *testing.T) { + t.Setenv("CINODE_LISTEN_PORT", "0") + ctx, cancel := context.WithCancel(context.Background()) go func() { time.Sleep(10 * time.Millisecond)