Skip to content

Commit

Permalink
Add unit test
Browse files Browse the repository at this point in the history
Signed-off-by: Yanjun Zhou <[email protected]>
  • Loading branch information
yanjunz97 committed Dec 26, 2024
1 parent 5535fe4 commit 3637eec
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions pkg/nsx/services/subnetport/subnetport_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,24 @@ func TestSubnetPortService_ListSubnetPortByPodName(t *testing.T) {
assert.Equal(t, subnetPort2, subnetPorts[0])
}

func TestSubnetPortService_AllocatePortFromSubnet(t *testing.T) {
subnetPath := "subnet-path-1"
subnetId := "subnet-id-1"
subnetPortService := createSubnetPortService()
ok := subnetPortService.AllocatePortFromSubnet(&model.VpcSubnet{
Ipv4SubnetSize: common.Int64(16),
IpAddresses: []string{"10.0.0.1/28"},
Path: &subnetPath,
Id: &subnetId,
})
assert.True(t, ok)
empty := subnetPortService.IsEmptySubnet(subnetId, subnetPath)
assert.False(t, empty)
subnetPortService.ReleasePortInSubnet(subnetPath)
empty = subnetPortService.IsEmptySubnet(subnetId, subnetPath)
assert.True(t, empty)
}

func createSubnetPortService() *SubnetPortService {
return &SubnetPortService{
SubnetPortStore: &SubnetPortStore{ResourceStore: common.ResourceStore{
Expand Down

0 comments on commit 3637eec

Please sign in to comment.