2019-06-06 12:20:26 +03:00
|
|
|
// +build ignore
|
|
|
|
|
2019-06-10 11:33:19 +03:00
|
|
|
package home
|
2019-04-25 14:57:03 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
2020-07-20 12:32:14 +03:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-04-25 14:57:03 +03:00
|
|
|
)
|
|
|
|
|
2019-06-06 12:20:26 +03:00
|
|
|
func TestDoUpdate(t *testing.T) {
|
2019-04-25 14:57:03 +03:00
|
|
|
config.DNS.Port = 0
|
2020-02-13 18:42:07 +03:00
|
|
|
Context.workDir = "..." // set absolute path
|
2019-06-27 15:23:48 +03:00
|
|
|
newver := "v0.96"
|
|
|
|
|
|
|
|
data := `{
|
|
|
|
"version": "v0.96",
|
|
|
|
"announcement": "AdGuard Home v0.96 is now available!",
|
|
|
|
"announcement_url": "",
|
2020-07-20 12:32:14 +03:00
|
|
|
"download_windows_amd64": "https://static.adguard.com/adguardhome/beta/AdGuardHome_windows_amd64.zip",
|
|
|
|
"download_windows_386": "https://static.adguard.com/adguardhome/beta/AdGuardHome_windows_386.zip",
|
|
|
|
"download_darwin_amd64": "https://static.adguard.com/adguardhome/beta/AdGuardHome_darwin_amd64.zip",
|
|
|
|
"download_darwin_386": "https://static.adguard.com/adguardhome/beta/AdGuardHome_darwin_386.zip",
|
|
|
|
"download_linux_amd64": "https://static.adguard.com/adguardhome/beta/AdGuardHome_linux_amd64.tar.gz",
|
|
|
|
"download_linux_386": "https://static.adguard.com/adguardhome/beta/AdGuardHome_linux_386.tar.gz",
|
|
|
|
"download_linux_arm": "https://static.adguard.com/adguardhome/beta/AdGuardHome_linux_armv6.tar.gz",
|
|
|
|
"download_linux_armv5": "https://static.adguard.com/adguardhome/beta/AdGuardHome_linux_armv5.tar.gz",
|
|
|
|
"download_linux_armv6": "https://static.adguard.com/adguardhome/beta/AdGuardHome_linux_armv6.tar.gz",
|
|
|
|
"download_linux_armv7": "https://static.adguard.com/adguardhome/beta/AdGuardHome_linux_armv7.tar.gz",
|
|
|
|
"download_linux_arm64": "https://static.adguard.com/adguardhome/beta/AdGuardHome_linux_arm64.tar.gz",
|
|
|
|
"download_linux_mips": "https://static.adguard.com/adguardhome/beta/AdGuardHome_linux_mips_softfloat.tar.gz",
|
|
|
|
"download_linux_mipsle": "https://static.adguard.com/adguardhome/beta/AdGuardHome_linux_mipsle_softfloat.tar.gz",
|
|
|
|
"download_linux_mips64": "https://static.adguard.com/adguardhome/beta/AdGuardHome_linux_mips64_softfloat.tar.gz",
|
|
|
|
"download_linux_mips64le": "https://static.adguard.com/adguardhome/beta/AdGuardHome_linux_mips64le_softfloat.tar.gz",
|
|
|
|
"download_freebsd_386": "https://static.adguard.com/adguardhome/beta/AdGuardHome_freebsd_386.tar.gz",
|
|
|
|
"download_freebsd_amd64": "https://static.adguard.com/adguardhome/beta/AdGuardHome_freebsd_amd64.tar.gz",
|
|
|
|
"download_freebsd_arm": "https://static.adguard.com/adguardhome/beta/AdGuardHome_freebsd_armv6.tar.gz",
|
|
|
|
"download_freebsd_armv5": "https://static.adguard.com/adguardhome/beta/AdGuardHome_freebsd_armv5.tar.gz",
|
|
|
|
"download_freebsd_armv6": "https://static.adguard.com/adguardhome/beta/AdGuardHome_freebsd_armv6.tar.gz",
|
|
|
|
"download_freebsd_armv7": "https://static.adguard.com/adguardhome/beta/AdGuardHome_freebsd_armv7.tar.gz",
|
|
|
|
"download_freebsd_arm64": "https://static.adguard.com/adguardhome/beta/AdGuardHome_freebsd_arm64.tar.gz"
|
2019-06-27 15:23:48 +03:00
|
|
|
}`
|
|
|
|
uu, err := getUpdateInfo([]byte(data))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("getUpdateInfo: %s", err)
|
|
|
|
}
|
|
|
|
|
2019-04-25 14:57:03 +03:00
|
|
|
u := updateInfo{
|
2020-07-20 12:32:14 +03:00
|
|
|
pkgURL: "https://static.adguard.com/adguardhome/beta/AdGuardHome_linux_armv6.tar.gz",
|
2020-02-13 18:42:07 +03:00
|
|
|
pkgName: Context.workDir + "/agh-update-" + newver + "/AdGuardHome_linux_amd64.tar.gz",
|
2019-06-27 15:23:48 +03:00
|
|
|
newVer: newver,
|
2020-02-13 18:42:07 +03:00
|
|
|
updateDir: Context.workDir + "/agh-update-" + newver,
|
|
|
|
backupDir: Context.workDir + "/agh-backup",
|
|
|
|
configName: Context.workDir + "/AdGuardHome.yaml",
|
2020-10-30 13:32:02 +03:00
|
|
|
updateConfigName: Context.workDir + "/agh-update-" + newver + "/AdGuardHome/internal/AdGuardHome.yaml",
|
2020-02-13 18:42:07 +03:00
|
|
|
curBinName: Context.workDir + "/AdGuardHome",
|
|
|
|
bkpBinName: Context.workDir + "/agh-backup/AdGuardHome",
|
2020-10-30 13:32:02 +03:00
|
|
|
newBinName: Context.workDir + "/agh-update-" + newver + "/AdGuardHome/internal/AdGuardHome",
|
2019-04-25 14:57:03 +03:00
|
|
|
}
|
2019-06-27 15:23:48 +03:00
|
|
|
|
2020-07-20 12:32:14 +03:00
|
|
|
assert.Equal(t, uu.pkgURL, u.pkgURL)
|
|
|
|
assert.Equal(t, uu.pkgName, u.pkgName)
|
|
|
|
assert.Equal(t, uu.newVer, u.newVer)
|
|
|
|
assert.Equal(t, uu.updateDir, u.updateDir)
|
|
|
|
assert.Equal(t, uu.backupDir, u.backupDir)
|
|
|
|
assert.Equal(t, uu.configName, u.configName)
|
|
|
|
assert.Equal(t, uu.updateConfigName, u.updateConfigName)
|
|
|
|
assert.Equal(t, uu.curBinName, u.curBinName)
|
|
|
|
assert.Equal(t, uu.bkpBinName, u.bkpBinName)
|
|
|
|
assert.Equal(t, uu.newBinName, u.newBinName)
|
2019-06-27 15:23:48 +03:00
|
|
|
|
2019-04-25 14:57:03 +03:00
|
|
|
e := doUpdate(&u)
|
|
|
|
if e != nil {
|
|
|
|
t.Fatalf("FAILED: %s", e)
|
|
|
|
}
|
|
|
|
os.RemoveAll(u.backupDir)
|
|
|
|
}
|
|
|
|
|
2019-06-06 12:20:26 +03:00
|
|
|
func TestTargzFileUnpack(t *testing.T) {
|
2020-07-20 12:32:14 +03:00
|
|
|
fn := "../dist/AdGuardHome_linux_amd64.tar.gz"
|
|
|
|
outdir := "../test-unpack"
|
|
|
|
defer os.RemoveAll(outdir)
|
2020-12-07 16:04:53 +03:00
|
|
|
_ = os.Mkdir(outdir, 0o755)
|
2019-06-05 15:27:32 +03:00
|
|
|
files, e := targzFileUnpack(fn, outdir)
|
|
|
|
if e != nil {
|
|
|
|
t.Fatalf("FAILED: %s", e)
|
|
|
|
}
|
|
|
|
t.Logf("%v", files)
|
|
|
|
}
|
|
|
|
|
2019-06-06 12:20:26 +03:00
|
|
|
func TestZipFileUnpack(t *testing.T) {
|
2020-07-20 12:32:14 +03:00
|
|
|
fn := "../dist/AdGuardHome_windows_amd64.zip"
|
|
|
|
outdir := "../test-unpack"
|
2020-12-07 16:04:53 +03:00
|
|
|
_ = os.Mkdir(outdir, 0o755)
|
2019-06-05 15:33:09 +03:00
|
|
|
files, e := zipFileUnpack(fn, outdir)
|
2019-04-25 14:57:03 +03:00
|
|
|
if e != nil {
|
|
|
|
t.Fatalf("FAILED: %s", e)
|
|
|
|
}
|
2019-06-05 15:33:09 +03:00
|
|
|
t.Logf("%v", files)
|
2019-04-25 14:57:03 +03:00
|
|
|
os.RemoveAll(outdir)
|
|
|
|
}
|