-
Notifications
You must be signed in to change notification settings - Fork 0
/
syncer_test.go
115 lines (97 loc) · 2.44 KB
/
syncer_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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package solc
import (
"context"
"runtime"
"testing"
"time"
"github.com/stretchr/testify/assert"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
)
// TestSyncer tests the Syncer but as well builds the releases in the releases path.
func TestSyncer(t *testing.T) {
logger, err := GetDevelopmentLogger(zapcore.DebugLevel)
assert.NoError(t, err)
assert.NotNil(t, logger)
zap.ReplaceGlobals(logger)
tests := []struct {
name string
releasesPath string
expectedGOOS string
config *Config
wantSyncErr bool
}{
{
name: "Download Binaries Successfully",
expectedGOOS: runtime.GOOS,
config: func() *Config {
config, err := NewDefaultConfig()
assert.NoError(t, err)
assert.NotNil(t, config)
return config
}(),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// We need to set timeout to 5 minutes so we can debug the HTTP requests.
tt.config.SetHttpClientTimeout(300 * time.Second)
s, err := New(context.TODO(), tt.config)
assert.NoError(t, err)
assert.NotNil(t, s)
err = s.Sync()
if tt.wantSyncErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
assert.NotNil(t, s.LastSyncTime())
})
}
}
func TestSyncOnce(t *testing.T) {
logger, err := GetDevelopmentLogger(zapcore.DebugLevel)
assert.NoError(t, err)
assert.NotNil(t, logger)
zap.ReplaceGlobals(logger)
tests := []struct {
name string
releasesPath string
expectedGOOS string
config *Config
wantSyncErr bool
}{
{
name: "Download Binaries Successfully",
expectedGOOS: runtime.GOOS,
config: func() *Config {
config, err := NewDefaultConfig()
assert.NoError(t, err)
assert.NotNil(t, config)
return config
}(),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
// We need to set timeout to 1.5 minutes so we can debug the HTTP requests.
tt.config.SetHttpClientTimeout(90 * time.Second)
s, err := New(context.TODO(), tt.config)
assert.NoError(t, err)
assert.NotNil(t, s)
latestRelease, err := s.GetLatestRelease()
assert.NoError(t, err)
assert.NotNil(t, latestRelease)
// Remove release from path so we can test the SyncOne method.
err = s.RemoveBinary(latestRelease.TagName)
assert.NoError(t, err)
err = s.SyncOne(latestRelease)
if tt.wantSyncErr {
assert.Error(t, err)
} else {
assert.NoError(t, err)
}
assert.NotNil(t, s.LastSyncTime())
})
}
}