Try fixing Windows tests

This commit is contained in:
Mislav Marohnić 2020-09-02 22:11:46 +02:00
parent 6933c381bf
commit 02a057a709
3 changed files with 27 additions and 15 deletions

View file

@ -103,7 +103,7 @@ func Test_NewCmdCreate(t *testing.T) {
},
{
name: "notes from file",
args: "v1.2.3 -F" + tf.Name(),
args: fmt.Sprintf(`v1.2.3 -F '%s'`, tf.Name()),
isTTY: true,
want: CreateOptions{
TagName: "v1.2.3",

View file

@ -6,7 +6,6 @@ import (
"net/http"
"os"
"path/filepath"
"strings"
"testing"
"github.com/cli/cli/internal/ghrepo"
@ -129,9 +128,9 @@ func Test_downloadRun(t *testing.T) {
wantStdout: ``,
wantStderr: ``,
wantFiles: []string{
"./linux.tgz",
"./windows-32bit.zip",
"./windows-64bit.zip",
"linux.tgz",
"windows-32bit.zip",
"windows-64bit.zip",
},
},
{
@ -146,8 +145,8 @@ func Test_downloadRun(t *testing.T) {
wantStdout: ``,
wantStderr: ``,
wantFiles: []string{
"./tmp/assets/windows-32bit.zip",
"./tmp/assets/windows-64bit.zip",
"tmp/assets/windows-32bit.zip",
"tmp/assets/windows-64bit.zip",
},
},
{
@ -221,7 +220,11 @@ func listFiles(dir string) ([]string, error) {
var files []string
err := filepath.Walk(dir, func(p string, f os.FileInfo, err error) error {
if !f.IsDir() {
files = append(files, "."+strings.TrimPrefix(p, dir))
rp, err := filepath.Rel(dir, p)
if err != nil {
return err
}
files = append(files, filepath.ToSlash(rp))
}
return err
})

View file

@ -56,14 +56,13 @@ func AssetsFromArgs(args []string) (assets []*AssetForUpload, err error) {
}
func typeForFilename(fn string) string {
fn = strings.ToLower(fn)
if strings.HasSuffix(fn, ".tar.gz") {
return "application/x-gtar"
}
ext := path.Ext(fn)
ext := fileExt(fn)
switch ext {
case ".tgz":
case "zip":
return "application/zip"
case "js":
return "application/javascript"
case ".tgz", ".tar.gz":
return "application/x-gtar"
case ".bz2":
return "application/x-bzip2"
@ -71,6 +70,8 @@ func typeForFilename(fn string) string {
return "application/x-apple-diskimage"
case ".rpm":
return "application/x-rpm"
case ".deb":
return "application/x-debian-package"
}
t := mime.TypeByExtension(ext)
@ -80,6 +81,14 @@ func typeForFilename(fn string) string {
return t
}
func fileExt(fn string) string {
fn = strings.ToLower(fn)
if strings.HasSuffix(fn, ".tar.gz") {
return ".tar.gz"
}
return path.Ext(fn)
}
func ConcurrentUpload(httpClient *http.Client, uploadURL string, numWorkers int, assets []*AssetForUpload) error {
if numWorkers == 0 {
return errors.New("the number of concurrent workers needs to be greater than 0")