Pull request 2255: 4923 Fix tests

Updates #4923.

Squashed commit of the following:

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

    dhcpsvc: close db

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

    dhcpsvc: fix test paths
This commit is contained in:
Eugene Burkov 2024-07-10 13:03:36 +03:00
parent e269260fbe
commit 130560b104
2 changed files with 6 additions and 2 deletions

View File

@ -106,6 +106,9 @@ func (srv *DHCPServer) dbLoad(ctx context.Context) (err error) {
return nil return nil
} }
defer func() {
err = errors.WithDeferred(err, file.Close())
}()
dl := &dataLeases{} dl := &dataLeases{}
err = json.NewDecoder(file).Decode(dl) err = json.NewDecoder(file).Decode(dl)

View File

@ -4,6 +4,7 @@ import (
"io/fs" "io/fs"
"net/netip" "net/netip"
"os" "os"
"path"
"path/filepath" "path/filepath"
"strings" "strings"
"testing" "testing"
@ -19,14 +20,14 @@ import (
var testdata = os.DirFS("testdata") var testdata = os.DirFS("testdata")
// newTempDB copies the leases database file located in the testdata FS, under // 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. // copied file.
func newTempDB(tb testing.TB) (dst string) { func newTempDB(tb testing.TB) (dst string) {
tb.Helper() tb.Helper()
const filename = "leases.json" 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) require.NoError(tb, err)
dst = filepath.Join(tb.TempDir(), filename) dst = filepath.Join(tb.TempDir(), filename)