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