forked from exercism/cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli_test.go
More file actions
50 lines (42 loc) · 951 Bytes
/
cli_test.go
File metadata and controls
50 lines (42 loc) · 951 Bytes
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
package cli
import (
"fmt"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/assert"
)
func TestIsUpToDate(t *testing.T) {
tests := []struct {
cliVersion string
releaseTag string
ok bool
}{
{"1.0.0", "v1.0.1", false},
{"2.0.1", "v2.0.1", true},
}
for _, test := range tests {
c := &CLI{
Version: test.cliVersion,
LatestRelease: &Release{TagName: test.releaseTag},
}
ok, err := c.IsUpToDate()
assert.NoError(t, err)
assert.Equal(t, test.ok, ok, test.cliVersion)
}
}
func TestIsUpToDateWithoutRelease(t *testing.T) {
fakeEndpoint := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, `{"tag_name": "v2.0.0"}`)
})
ts := httptest.NewServer(fakeEndpoint)
defer ts.Close()
LatestReleaseURL = ts.URL
c := &CLI{
Version: "1.0.0",
}
ok, err := c.IsUpToDate()
assert.NoError(t, err)
assert.False(t, ok)
assert.NotNil(t, c.LatestRelease)
}