mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-12-15 03:02:07 +03:00
93ab0fde23
Squashed commit of the following:
commit 402ac873839fcf4dfb762872497b740bd55b2dcc
Merge: 209e1b171 af38476ef
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Sep 21 16:46:47 2023 +0300
Merge branch 'master' into AG-23168-imp-updater-tests
commit 209e1b171cb4c55d177ef5a4198cf24c2bc41195
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Sep 21 14:09:43 2023 +0300
updater: fix windows build
commit d112ca53540e0c999fe126442e8c526ff7e33bf5
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Wed Sep 20 18:57:54 2023 +0300
all: imp tests, docs
commit f940724f81a90af6c07de523c8fcce66240dbec9
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Wed Sep 20 16:07:48 2023 +0300
all: imp tests
commit 8915818e81360a7f6ff5b652a983ca034ad6d0c4
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Tue Sep 19 19:33:20 2023 +0300
all: add test
commit c1cb8df2b056cefc5d7f1b32c089cd0ede0af9d2
Author: Stanislav Chzhen <s.chzhen@adguard.com>
Date: Thu Sep 14 19:12:47 2023 +0300
updater: imp tests
108 lines
2.7 KiB
Go
108 lines
2.7 KiB
Go
package updater
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/AdguardTeam/AdGuardHome/internal/aghtest"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestUpdater_internal(t *testing.T) {
|
|
wd := t.TempDir()
|
|
|
|
exePathUnix := filepath.Join(wd, "AdGuardHome.exe")
|
|
exePathWindows := filepath.Join(wd, "AdGuardHome")
|
|
yamlPath := filepath.Join(wd, "AdGuardHome.yaml")
|
|
readmePath := filepath.Join(wd, "README.md")
|
|
licensePath := filepath.Join(wd, "LICENSE.txt")
|
|
|
|
require.NoError(t, os.WriteFile(exePathUnix, []byte("AdGuardHome.exe"), 0o755))
|
|
require.NoError(t, os.WriteFile(exePathWindows, []byte("AdGuardHome"), 0o755))
|
|
require.NoError(t, os.WriteFile(yamlPath, []byte("AdGuardHome.yaml"), 0o644))
|
|
require.NoError(t, os.WriteFile(readmePath, []byte("README.md"), 0o644))
|
|
require.NoError(t, os.WriteFile(licensePath, []byte("LICENSE.txt"), 0o644))
|
|
|
|
testCases := []struct {
|
|
name string
|
|
exeName string
|
|
os string
|
|
archiveName string
|
|
}{{
|
|
name: "unix",
|
|
os: "linux",
|
|
exeName: "AdGuardHome",
|
|
archiveName: "AdGuardHome.tar.gz",
|
|
}, {
|
|
name: "windows",
|
|
os: "windows",
|
|
exeName: "AdGuardHome.exe",
|
|
archiveName: "AdGuardHome.zip",
|
|
}}
|
|
|
|
for _, tc := range testCases {
|
|
exePath := filepath.Join(wd, tc.exeName)
|
|
|
|
// start server for returning package file
|
|
pkgData, err := os.ReadFile(filepath.Join("testdata", tc.archiveName))
|
|
require.NoError(t, err)
|
|
|
|
fakeClient, fakeURL := aghtest.StartHTTPServer(t, pkgData)
|
|
fakeURL = fakeURL.JoinPath(tc.archiveName)
|
|
|
|
u := NewUpdater(&Config{
|
|
Client: fakeClient,
|
|
GOOS: tc.os,
|
|
Version: "v0.103.0",
|
|
ExecPath: exePath,
|
|
WorkDir: wd,
|
|
ConfName: yamlPath,
|
|
})
|
|
|
|
u.newVersion = "v0.103.1"
|
|
u.packageURL = fakeURL.String()
|
|
|
|
require.NoError(t, u.prepare())
|
|
require.NoError(t, u.downloadPackageFile())
|
|
require.NoError(t, u.unpack())
|
|
require.NoError(t, u.backup(false))
|
|
require.NoError(t, u.replace())
|
|
|
|
u.clean()
|
|
|
|
// check backup files
|
|
d, err := os.ReadFile(filepath.Join(wd, "agh-backup", "AdGuardHome.yaml"))
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "AdGuardHome.yaml", string(d))
|
|
|
|
d, err = os.ReadFile(filepath.Join(wd, "agh-backup", tc.exeName))
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, tc.exeName, string(d))
|
|
|
|
// check updated files
|
|
d, err = os.ReadFile(exePath)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "1", string(d))
|
|
|
|
d, err = os.ReadFile(readmePath)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "2", string(d))
|
|
|
|
d, err = os.ReadFile(licensePath)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "3", string(d))
|
|
|
|
d, err = os.ReadFile(yamlPath)
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, "AdGuardHome.yaml", string(d))
|
|
}
|
|
}
|