2019-06-06 10:20:26 +01:00
|
|
|
// +build ignore
|
|
|
|
|
2019-06-10 09:33:19 +01:00
|
|
|
package home
|
2019-04-25 12:57:03 +01:00
|
|
|
|
|
|
|
import (
|
|
|
|
"os"
|
|
|
|
"testing"
|
2020-07-20 10:32:14 +01:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2019-04-25 12:57:03 +01:00
|
|
|
)
|
|
|
|
|
2019-06-06 10:20:26 +01:00
|
|
|
func TestDoUpdate(t *testing.T) {
|
2019-04-25 12:57:03 +01:00
|
|
|
config.DNS.Port = 0
|
2020-02-13 15:42:07 +00:00
|
|
|
Context.workDir = "..." // set absolute path
|
2019-06-27 13:23:48 +01:00
|
|
|
newver := "v0.96"
|
|
|
|
|
|
|
|
data := `{
|
|
|
|
"version": "v0.96",
|
|
|
|
"announcement": "AdGuard Home v0.96 is now available!",
|
|
|
|
"announcement_url": "",
|
2020-07-20 10:32:14 +01: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 13:23:48 +01:00
|
|
|
}`
|
|
|
|
uu, err := getUpdateInfo([]byte(data))
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("getUpdateInfo: %s", err)
|
|
|
|
}
|
|
|
|
|
2019-04-25 12:57:03 +01:00
|
|
|
u := updateInfo{
|
2020-07-20 10:32:14 +01:00
|
|
|
pkgURL: "https://static.adguard.com/adguardhome/beta/AdGuardHome_linux_armv6.tar.gz",
|
2020-02-13 15:42:07 +00:00
|
|
|
pkgName: Context.workDir + "/agh-update-" + newver + "/AdGuardHome_linux_amd64.tar.gz",
|
2019-06-27 13:23:48 +01:00
|
|
|
newVer: newver,
|
2020-02-13 15:42:07 +00:00
|
|
|
updateDir: Context.workDir + "/agh-update-" + newver,
|
|
|
|
backupDir: Context.workDir + "/agh-backup",
|
|
|
|
configName: Context.workDir + "/AdGuardHome.yaml",
|
|
|
|
updateConfigName: Context.workDir + "/agh-update-" + newver + "/AdGuardHome/AdGuardHome.yaml",
|
|
|
|
curBinName: Context.workDir + "/AdGuardHome",
|
|
|
|
bkpBinName: Context.workDir + "/agh-backup/AdGuardHome",
|
|
|
|
newBinName: Context.workDir + "/agh-update-" + newver + "/AdGuardHome/AdGuardHome",
|
2019-04-25 12:57:03 +01:00
|
|
|
}
|
2019-06-27 13:23:48 +01:00
|
|
|
|
2020-07-20 10:32:14 +01: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 13:23:48 +01:00
|
|
|
|
2019-04-25 12:57:03 +01:00
|
|
|
e := doUpdate(&u)
|
|
|
|
if e != nil {
|
|
|
|
t.Fatalf("FAILED: %s", e)
|
|
|
|
}
|
|
|
|
os.RemoveAll(u.backupDir)
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:20:26 +01:00
|
|
|
func TestTargzFileUnpack(t *testing.T) {
|
2020-07-20 10:32:14 +01:00
|
|
|
fn := "../dist/AdGuardHome_linux_amd64.tar.gz"
|
|
|
|
outdir := "../test-unpack"
|
|
|
|
defer os.RemoveAll(outdir)
|
2019-06-05 13:27:32 +01:00
|
|
|
_ = os.Mkdir(outdir, 0755)
|
|
|
|
files, e := targzFileUnpack(fn, outdir)
|
|
|
|
if e != nil {
|
|
|
|
t.Fatalf("FAILED: %s", e)
|
|
|
|
}
|
|
|
|
t.Logf("%v", files)
|
|
|
|
}
|
|
|
|
|
2019-06-06 10:20:26 +01:00
|
|
|
func TestZipFileUnpack(t *testing.T) {
|
2020-07-20 10:32:14 +01:00
|
|
|
fn := "../dist/AdGuardHome_windows_amd64.zip"
|
|
|
|
outdir := "../test-unpack"
|
2019-04-25 12:57:03 +01:00
|
|
|
_ = os.Mkdir(outdir, 0755)
|
2019-06-05 13:33:09 +01:00
|
|
|
files, e := zipFileUnpack(fn, outdir)
|
2019-04-25 12:57:03 +01:00
|
|
|
if e != nil {
|
|
|
|
t.Fatalf("FAILED: %s", e)
|
|
|
|
}
|
2019-06-05 13:33:09 +01:00
|
|
|
t.Logf("%v", files)
|
2019-04-25 12:57:03 +01:00
|
|
|
os.RemoveAll(outdir)
|
|
|
|
}
|