Skip to content

Commit

Permalink
Fix issue with wrong test file selected, and small potential panic in…
Browse files Browse the repository at this point in the history
… get next ip
  • Loading branch information
NHAS committed Apr 27, 2024
1 parent d860c12 commit 816a701
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions internal/data/dhcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package data

import (
"context"
"errors"
"math"
"math/rand"
"net"
Expand Down Expand Up @@ -31,6 +32,9 @@ func getNextIP(subnet string) (string, error) {

used, _ := cidr.Mask.Size()
addresses := int(math.Pow(2, float64(32-used))) - 2 // Do not allocate largest address or 0
if addresses < 1 {
return "", errors.New("no addresses available")
}

// Choose a random number that cannot be 0
addressAttempt := rand.Intn(addresses) + 1
Expand Down
2 changes: 1 addition & 1 deletion internal/users/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestMain(m *testing.M) {
}

func setupWgTest() error {
if err := config.Load("../config/test_in_memory_db.json"); err != nil {
if err := config.Load("../config/testing_config.json"); err != nil {
return err
}

Expand Down

0 comments on commit 816a701

Please sign in to comment.