all: resync fix

This commit is contained in:
Ainar Garipov 2024-10-02 20:25:07 +03:00
parent e8fd4b1872
commit ee1eb80786
5 changed files with 54 additions and 11 deletions

View file

@ -7,6 +7,7 @@ import (
"bufio" "bufio"
"fmt" "fmt"
"io" "io"
"io/fs"
"os" "os"
"os/exec" "os/exec"
"path" "path"
@ -21,8 +22,8 @@ import (
// Default file and directory permissions. // Default file and directory permissions.
const ( const (
DefaultPermDir = 0o700 DefaultPermDir fs.FileMode = 0o700
DefaultPermFile = 0o600 DefaultPermFile fs.FileMode = 0o600
) )
// Unsupported is a helper that returns a wrapped [errors.ErrUnsupported]. // Unsupported is a helper that returns a wrapped [errors.ErrUnsupported].

View file

@ -1,10 +1,12 @@
package configmigrate_test package configmigrate_test
import ( import (
"bytes"
"io/fs" "io/fs"
"os" "os"
"path" "path"
"path/filepath" "path/filepath"
"runtime"
"testing" "testing"
"github.com/AdguardTeam/AdGuardHome/internal/configmigrate" "github.com/AdguardTeam/AdGuardHome/internal/configmigrate"
@ -191,10 +193,6 @@ func TestMigrateConfig_Migrate(t *testing.T) {
yamlEqFunc: require.YAMLEq, yamlEqFunc: require.YAMLEq,
name: "v27", name: "v27",
targetVersion: 27, targetVersion: 27,
}, {
yamlEqFunc: require.YAMLEq,
name: "v29",
targetVersion: 29,
}} }}
for _, tc := range testCases { for _, tc := range testCases {
@ -217,3 +215,43 @@ func TestMigrateConfig_Migrate(t *testing.T) {
}) })
} }
} }
// TODO(a.garipov): Consider ways of merging into the previous one.
func TestMigrateConfig_Migrate_v29(t *testing.T) {
const (
pathUnix = `/path/to/file.txt`
userDirPatUnix = `TestMigrateConfig_Migrate/v29/data/userfilters/*`
pathWindows = `C:\path\to\file.txt`
userDirPatWindows = `TestMigrateConfig_Migrate\v29\data\userfilters\*`
)
pathToReplace := pathUnix
patternToReplace := userDirPatUnix
if runtime.GOOS == "windows" {
pathToReplace = pathWindows
patternToReplace = userDirPatWindows
}
body, err := fs.ReadFile(testdata, "TestMigrateConfig_Migrate/v29/input.yml")
require.NoError(t, err)
body = bytes.ReplaceAll(body, []byte("FILEPATH"), []byte(pathToReplace))
wantBody, err := fs.ReadFile(testdata, "TestMigrateConfig_Migrate/v29/output.yml")
require.NoError(t, err)
wantBody = bytes.ReplaceAll(wantBody, []byte("FILEPATH"), []byte(pathToReplace))
wantBody = bytes.ReplaceAll(wantBody, []byte("USERFILTERSPATH"), []byte(patternToReplace))
migrator := configmigrate.New(&configmigrate.Config{
WorkingDir: t.Name(),
DataDir: "TestMigrateConfig_Migrate/v29/data",
})
newBody, upgraded, err := migrator.Migrate(body, 29)
require.NoError(t, err)
require.True(t, upgraded)
require.YAMLEq(t, string(wantBody), string(newBody))
}

View file

@ -45,7 +45,7 @@ filters:
- url: https://adaway.org/hosts.txt - url: https://adaway.org/hosts.txt
name: AdAway name: AdAway
enabled: false enabled: false
- url: /path/to/file.txt - url: FILEPATH
name: Local Filter name: Local Filter
enabled: false enabled: false
clients: clients:

View file

@ -27,8 +27,8 @@ filtering:
parental_enabled: false parental_enabled: false
safebrowsing_enabled: false safebrowsing_enabled: false
safe_fs_patterns: safe_fs_patterns:
- TestMigrateConfig_Migrate/v29/data/userfilters/* - USERFILTERSPATH
- /path/to/file.txt - FILEPATH
safe_search: safe_search:
enabled: false enabled: false
bing: true bing: true
@ -48,7 +48,7 @@ filters:
- url: https://adaway.org/hosts.txt - url: https://adaway.org/hosts.txt
name: AdAway name: AdAway
enabled: false enabled: false
- url: /path/to/file.txt - url: FILEPATH
name: Local Filter name: Local Filter
enabled: false enabled: false
clients: clients:

View file

@ -584,7 +584,11 @@ func TestSafeSearch(t *testing.T) {
req := createTestMessage(tc.host) req := createTestMessage(tc.host)
var reply *dns.Msg var reply *dns.Msg
reply, _, err = client.Exchange(req, addr) require.Eventually(t, func() (ok bool) {
reply, _, err = client.Exchange(req, addr)
return err == nil
}, testTimeout*10, testTimeout)
require.NoErrorf(t, err, "couldn't talk to server %s: %s", addr, err) require.NoErrorf(t, err, "couldn't talk to server %s: %s", addr, err)
if tc.wantCNAME != "" { if tc.wantCNAME != "" {