Pull request 2405: AGDNS-2374-updater-slog

Squashed commit of the following:

commit 89c3df471964b674b7ddafeb22566e5be9b56a13
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Mon May 12 18:59:39 2025 +0300

    updater: imp log

commit d78ba4368027ddcbb41c10fbf09d43fe0721dc4c
Merge: 68410954c 187b759fc
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Mon May 12 18:53:33 2025 +0300

    Merge branch 'master' into AGDNS-2374-updater-slog

commit 68410954c80d76b2adafe4ed28fafdd6b6b6daae
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Apr 30 15:54:30 2025 +0300

    updater: imp docs

commit 99a705218fb849bb59dee5b801c5279a501bcf98
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Wed Apr 30 15:40:30 2025 +0300

    updater: imp docs, logs

commit 2a83ee3ebf9610a2703d99ec6a6b327a315f6cce
Author: Ainar Garipov <A.Garipov@AdGuard.COM>
Date:   Tue Apr 29 21:01:02 2025 +0300

    updater: use slog
This commit is contained in:
Ainar Garipov
2025-05-13 14:42:33 +03:00
parent 187b759fc6
commit ae840c9c96
7 changed files with 244 additions and 126 deletions

View File

@@ -10,17 +10,21 @@ import (
"path/filepath"
"runtime"
"testing"
"time"
"github.com/AdguardTeam/AdGuardHome/internal/updater"
"github.com/AdguardTeam/AdGuardHome/internal/version"
"github.com/AdguardTeam/golibs/logutil/slogutil"
"github.com/AdguardTeam/golibs/testutil"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func TestMain(m *testing.M) {
testutil.DiscardLogOutput(m)
}
// testTimeout is the common timeout for tests.
const testTimeout = 1 * time.Second
// testLogger is the common logger for tests.
var testLogger = slogutil.NewDiscardLogger()
func TestUpdater_Update(t *testing.T) {
const jsonData = `{
@@ -73,6 +77,7 @@ func TestUpdater_Update(t *testing.T) {
u := updater.NewUpdater(&updater.Config{
Client: srv.Client(),
Logger: testLogger,
GOARCH: "amd64",
GOOS: "linux",
Version: "v0.103.0",
@@ -82,10 +87,12 @@ func TestUpdater_Update(t *testing.T) {
VersionCheckURL: versionCheckURL,
})
_, err = u.VersionInfo(false)
ctx := testutil.ContextWithTimeout(t, testTimeout)
_, err = u.VersionInfo(ctx, false)
require.NoError(t, err)
err = u.Update(true)
ctx = testutil.ContextWithTimeout(t, testTimeout)
err = u.Update(ctx, true)
require.NoError(t, err)
// check backup files
@@ -124,14 +131,15 @@ func TestUpdater_Update(t *testing.T) {
t.Skip("skipping config check test on windows")
}
err = u.Update(false)
err = u.Update(testutil.ContextWithTimeout(t, testTimeout), false)
assert.NoError(t, err)
})
t.Run("api_fail", func(t *testing.T) {
srv.Close()
err = u.Update(true)
err = u.Update(testutil.ContextWithTimeout(t, testTimeout), true)
var urlErr *url.Error
assert.ErrorAs(t, err, &urlErr)
})