-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwinsparkle_test.go
99 lines (82 loc) · 2.37 KB
/
winsparkle_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
package winsparkle_test
import (
"net/http"
"net/http/httptest"
"testing"
"text/template"
"time"
"github.com/abemedia/go-winsparkle"
_ "github.com/abemedia/go-winsparkle/dll"
)
func TestWinSparkle(t *testing.T) {
winsparkle.SetAppDetails("Test", "Test", "1.0")
winsparkle.SetAppcastURL(server(t, "1.0"))
last := winsparkle.GetLastCheckTime()
winsparkle.Init()
defer winsparkle.Cleanup()
winsparkle.CheckUpdateWithoutUI()
time.Sleep(time.Second) // Wait for update check.
if !winsparkle.GetLastCheckTime().After(last) {
t.Fatal("should check for updates")
}
}
func TestSetErrorCallback(t *testing.T) {
winsparkle.SetAppDetails("Test", "Test", "1.0")
winsparkle.SetAppcastURL("nope")
winsparkle.Init()
defer winsparkle.Cleanup()
ch := make(chan struct{}, 1)
winsparkle.SetErrorCallback(func() {
ch <- struct{}{}
})
winsparkle.CheckUpdateWithoutUI()
select {
case <-ch:
case <-time.After(time.Second):
t.Error("should call callback")
}
}
func TestSetCanShutdownCallback(t *testing.T) {
winsparkle.SetAppDetails("Test", "Test", "1.0.0")
winsparkle.SetAppcastURL(server(t, "2.0.0"))
winsparkle.Init()
defer winsparkle.Cleanup()
ch := make(chan struct{}, 1)
winsparkle.SetCanShutdownCallback(func() bool {
ch <- struct{}{}
return true
})
winsparkle.CheckUpdateWithUIAndInstall()
select {
case <-ch:
case <-time.After(time.Second):
t.Error("should call callback")
}
}
func server(t *testing.T, version string) string {
t.Helper()
s := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/xml")
appcastTmpl.Execute(w, struct {
Version string
Host string
}{version, r.Host})
}))
t.Cleanup(s.Close)
return s.URL
}
//nolint:lll
var appcastTmpl = template.Must(template.New("appcast").Parse(`<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:sparkle="http://www.andymatuschak.org/xml-namespaces/sparkle">
<channel>
<title>WinSparkle Test Appcast</title>
<description>Most recent updates to WinSparkle Test</description>
<language>en</language>
<item>
<title>Version {{.Version}}</title>
<description>This is an update.</description>
<pubDate>Mon, 28 Jan 2013 14:30:00 +0500</pubDate>
<enclosure sparkle:version="{{.Version}}" url="http://{{.Host}}/install.msi" length="0" type="application/octet-stream"/>
</item>
</channel>
</rss>`))