forked from deanishe/awgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflow_update_test.go
85 lines (71 loc) · 2.24 KB
/
workflow_update_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
// Copyright (c) 2019 Dean Jackson <[email protected]>
// MIT Licence applies http://opensource.org/licenses/MIT
package aw
import (
"errors"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
// ensure mockUpdater implements Updater
var _ Updater = (*mockUpdater)(nil)
type mockUpdater struct {
updateIntervalCalled bool
checkDueCalled bool
checkForUpdateCalled bool
updateAvailableCalled bool
installCalled bool
checkShouldFail bool
installShouldFail bool
}
// UpdateInterval implements Updater.
func (d *mockUpdater) UpdateInterval(_ time.Duration) {
d.updateIntervalCalled = true
}
// UpdateAvailable implements Updater.
func (d *mockUpdater) UpdateAvailable() bool {
d.updateAvailableCalled = true
return true
}
// CheckDue implements Updater.
func (d *mockUpdater) CheckDue() bool {
d.checkDueCalled = true
return true
}
// CheckForUpdate implements Updater.
func (d *mockUpdater) CheckForUpdate() error {
d.checkForUpdateCalled = true
if d.checkShouldFail {
return errors.New("check failed")
}
return nil
}
// Install implements Updater.
func (d *mockUpdater) Install() error {
d.installCalled = true
if d.installShouldFail {
return errors.New("install failed")
}
return nil
}
// Test that Workflow API responses match configured Updater's.
func TestWorkflowUpdater(t *testing.T) {
t.Parallel()
wf := New()
// false/fail when Updater is unset
assert.False(t, wf.UpdateCheckDue(), "unexpected UpdateCheckDue")
assert.False(t, wf.UpdateAvailable(), "unexpected UpdateAvailable")
assert.NotNil(t, wf.CheckForUpdate(), "CheckForUpdate succeeded")
assert.NotNil(t, wf.InstallUpdate(), "InstallUpdate succeeded")
// true/success with mockUpdater
u := &mockUpdater{}
_ = wf.Configure(Update(u))
assert.True(t, wf.UpdateCheckDue(), "unexpected UpdateCheckDue")
assert.True(t, u.checkDueCalled, "checkDue not called")
assert.True(t, wf.UpdateAvailable(), "unexpected UpdateAvailable")
assert.True(t, u.updateAvailableCalled, "updateAvailable not called")
assert.Nil(t, wf.CheckForUpdate(), "CheckForUpdate failed")
assert.True(t, u.checkForUpdateCalled, "checkForUpdate not called")
assert.Nil(t, wf.InstallUpdate(), "InstallUpdate failed")
assert.True(t, u.installCalled, "installCalled not called")
}