-
Notifications
You must be signed in to change notification settings - Fork 551
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: availableport enhancements (#3621)
* availableport extended for more params * typo private -> public OptionaParameters * Tests for updates in availableport * Corrections by Pantani * Removing excessive conditions * Changelog added * Avoids nil conn error. * Tests corrected for updated code. * Param update in `genAddr` to avoid type error * Faucet.Port int to uint * Editing 0 int to uint for Faucet.Port type * add table tests * remove unused double for * remove unused double for * format the code * Update changelog.md --------- Co-authored-by: Danilo Pantani <[email protected]> Co-authored-by: Jerónimo Albi <[email protected]>
- Loading branch information
1 parent
a86dd33
commit 3c9f058
Showing
6 changed files
with
155 additions
and
20 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package availableport_test | ||
|
||
import ( | ||
"fmt" | ||
"math/rand" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
|
||
"github.com/ignite/cli/ignite/pkg/availableport" | ||
) | ||
|
||
func TestFind(t *testing.T) { | ||
tests := []struct { | ||
name string | ||
n uint | ||
options []availableport.Options | ||
err error | ||
}{ | ||
{ | ||
name: "test 10 ports", | ||
n: 10, | ||
}, | ||
{ | ||
name: "invalid port range", | ||
n: 10, | ||
options: []availableport.Options{ | ||
availableport.WithMinPort(5), | ||
availableport.WithMaxPort(1), | ||
}, | ||
err: fmt.Errorf("invalid ports range: max < min (1 < 5)"), | ||
}, | ||
{ | ||
name: "invalid maximum port range", | ||
n: 10, | ||
options: []availableport.Options{ | ||
availableport.WithMinPort(55001), | ||
availableport.WithMaxPort(1), | ||
}, | ||
err: fmt.Errorf("invalid ports range: max < min (1 < 55001)"), | ||
}, | ||
{ | ||
name: "only invalid maximum port range", | ||
n: 10, | ||
options: []availableport.Options{ | ||
availableport.WithMaxPort(43999), | ||
}, | ||
err: fmt.Errorf("invalid ports range: max < min (43999 < 44000)"), | ||
}, | ||
{ | ||
name: "with randomizer", | ||
n: 100, | ||
options: []availableport.Options{ | ||
availableport.WithRandomizer(rand.New(rand.NewSource(2023))), | ||
availableport.WithMinPort(100), | ||
availableport.WithMaxPort(200), | ||
}, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
got, err := availableport.Find(tt.n, tt.options...) | ||
if tt.err != nil { | ||
require.Equal(t, tt.err, err) | ||
return | ||
} | ||
require.NoError(t, err) | ||
require.Len(t, got, int(tt.n)) | ||
|
||
seen := make(map[uint]struct{}) | ||
for _, val := range got { | ||
_, ok := seen[val] | ||
require.Falsef(t, ok, "duplicated port %d", val) | ||
seen[val] = struct{}{} | ||
} | ||
}) | ||
} | ||
} |
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