Skip to content

Commit

Permalink
Pull request 2255: 4923 Fix tests
Browse files Browse the repository at this point in the history
Updates #4923.

Squashed commit of the following:

commit 064d4aa
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Tue Jul 9 20:51:41 2024 +0300

    dhcpsvc: close db

commit d08b709
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date:   Tue Jul 9 20:37:42 2024 +0300

    dhcpsvc: fix test paths
  • Loading branch information
EugeneOne1 committed Jul 10, 2024
1 parent e269260 commit 130560b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions internal/dhcpsvc/db.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,9 @@ func (srv *DHCPServer) dbLoad(ctx context.Context) (err error) {

return nil
}
defer func() {
err = errors.WithDeferred(err, file.Close())
}()

dl := &dataLeases{}
err = json.NewDecoder(file).Decode(dl)
Expand Down
5 changes: 3 additions & 2 deletions internal/dhcpsvc/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"io/fs"
"net/netip"
"os"
"path"
"path/filepath"
"strings"
"testing"
Expand All @@ -19,14 +20,14 @@ import (
var testdata = os.DirFS("testdata")

// newTempDB copies the leases database file located in the testdata FS, under
// tb.Name()/leases.db, to a temporary directory and returns the path to the
// tb.Name()/leases.json, to a temporary directory and returns the path to the
// copied file.
func newTempDB(tb testing.TB) (dst string) {
tb.Helper()

const filename = "leases.json"

data, err := fs.ReadFile(testdata, filepath.Join(tb.Name(), filename))
data, err := fs.ReadFile(testdata, path.Join(tb.Name(), filename))
require.NoError(tb, err)

dst = filepath.Join(tb.TempDir(), filename)
Expand Down

0 comments on commit 130560b

Please sign in to comment.