Skip to content

Commit

Permalink
Use random port in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
byo committed Nov 19, 2023
1 parent 245b332 commit 4fa3eb5
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions pkg/cmd/cinode_web_proxy/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/cinode_web_proxy/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/public_node/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions pkg/cmd/public_node/root_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 4fa3eb5

Please sign in to comment.