Skip to content

Commit 321d72c

Browse files
committed
Test unzipExecutable
1 parent 210cffd commit 321d72c

File tree

3 files changed

+26
-9
lines changed

3 files changed

+26
-9
lines changed

commands/updater.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,6 @@ func (updater *Updater) timeToUpdate() bool {
4040
return writeTime(updateTimestampPath, time.Now().Add(wait))
4141
}
4242

43-
func (updater *Updater) latestReleaseNameAndVersion() (name, version string) {
44-
// Create Client with a stub Credentials
45-
c := github.Client{Credentials: &github.Credentials{Host: updater.Host}}
46-
name, _ = c.GhLatestTagName()
47-
version = strings.TrimPrefix(name, "v")
48-
49-
return
50-
}
51-
5243
func (updater *Updater) PromptForUpdate() (err error) {
5344
if !updater.timeToUpdate() {
5445
return
@@ -91,6 +82,15 @@ func (updater *Updater) Update() (err error) {
9182
return
9283
}
9384

85+
func (updater *Updater) latestReleaseNameAndVersion() (name, version string) {
86+
// Create Client with a stub Credentials
87+
c := github.Client{Credentials: &github.Credentials{Host: updater.Host}}
88+
name, _ = c.GhLatestTagName()
89+
version = strings.TrimPrefix(name, "v")
90+
91+
return
92+
}
93+
9494
func (updater *Updater) updateTo(releaseName, version string) (err error) {
9595
fmt.Printf("Updating gh to %s...\n", version)
9696
downloadURL := fmt.Sprintf("https://%s/jingweno/gh/releases/download/%s/gh_%s_%s_%s.zip", updater.Host, releaseName, version, runtime.GOOS, runtime.GOARCH)

commands/updater_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ package commands
33
import (
44
"fmt"
55
"github.com/bmizerany/assert"
6+
"io"
67
"io/ioutil"
78
"net/http"
89
"net/http/httptest"
10+
"os"
911
"path/filepath"
1012
"testing"
1113
)
@@ -28,3 +30,18 @@ func TestUpdater_downloadFile(t *testing.T) {
2830
assert.Equal(t, "1234", string(content))
2931
assert.Equal(t, "gh.zip", filepath.Base(path))
3032
}
33+
34+
func TestUpdater_unzipExecutable(t *testing.T) {
35+
target, _ := ioutil.TempFile("", "unzip-test")
36+
defer target.Close()
37+
38+
source, _ := os.Open(filepath.Join("..", "fixtures", "gh.zip"))
39+
defer source.Close()
40+
41+
_, err := io.Copy(target, source)
42+
assert.Equal(t, nil, err)
43+
44+
exec, err := unzipExecutable(target.Name())
45+
assert.Equal(t, nil, err)
46+
assert.Equal(t, "gh", filepath.Base(exec))
47+
}

fixtures/gh.zip

246 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)