Skip to content

Commit

Permalink
all: resync fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ainar-g committed Oct 2, 2024
1 parent e8fd4b1 commit ee1eb80
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 11 deletions.
5 changes: 3 additions & 2 deletions internal/aghos/os.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"bufio"
"fmt"
"io"
"io/fs"
"os"
"os/exec"
"path"
Expand All @@ -21,8 +22,8 @@ import (

// Default file and directory permissions.
const (
DefaultPermDir = 0o700
DefaultPermFile = 0o600
DefaultPermDir fs.FileMode = 0o700
DefaultPermFile fs.FileMode = 0o600
)

// Unsupported is a helper that returns a wrapped [errors.ErrUnsupported].
Expand Down
46 changes: 42 additions & 4 deletions internal/configmigrate/migrator_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package configmigrate_test

import (
"bytes"
"io/fs"
"os"
"path"
"path/filepath"
"runtime"
"testing"

"github.com/AdguardTeam/AdGuardHome/internal/configmigrate"
Expand Down Expand Up @@ -191,10 +193,6 @@ func TestMigrateConfig_Migrate(t *testing.T) {
yamlEqFunc: require.YAMLEq,
name: "v27",
targetVersion: 27,
}, {
yamlEqFunc: require.YAMLEq,
name: "v29",
targetVersion: 29,
}}

for _, tc := range testCases {
Expand All @@ -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))
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ filters:
- url: https://adaway.org/hosts.txt
name: AdAway
enabled: false
- url: /path/to/file.txt
- url: FILEPATH
name: Local Filter
enabled: false
clients:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ filtering:
parental_enabled: false
safebrowsing_enabled: false
safe_fs_patterns:
- TestMigrateConfig_Migrate/v29/data/userfilters/*
- /path/to/file.txt
- USERFILTERSPATH
- FILEPATH
safe_search:
enabled: false
bing: true
Expand All @@ -48,7 +48,7 @@ filters:
- url: https://adaway.org/hosts.txt
name: AdAway
enabled: false
- url: /path/to/file.txt
- url: FILEPATH
name: Local Filter
enabled: false
clients:
Expand Down
6 changes: 5 additions & 1 deletion internal/dnsforward/dnsforward_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -584,7 +584,11 @@ func TestSafeSearch(t *testing.T) {
req := createTestMessage(tc.host)

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)

if tc.wantCNAME != "" {
Expand Down

0 comments on commit ee1eb80

Please sign in to comment.