提交 4f0312f3 编写于 作者: D David Calavera

Move `isEmptyDir` to the command utilities.

Removes duplicated test helper.
上级 6b14600f
......@@ -140,7 +140,7 @@ func getAssetsDirectory(assetsDir, tag string) (string, error) {
return "", fmt.Errorf("The assets directory doesn't exist: %s", assetsDir)
}
if utils.IsEmptyDir(assetsDir) {
if isEmptyDir(assetsDir) {
return "", fmt.Errorf("The assets directory is empty: %s", assetsDir)
}
......
......@@ -50,11 +50,3 @@ func assertAssetsDirSelected(t *testing.T, expectedDir, flagDir string) {
assert.Equal(t, nil, err)
assert.T(t, os.SameFile(fiExpected, fiAssets))
}
func createTempDir(t *testing.T) string {
dir, err := ioutil.TempDir("", "gh-test-")
if err != nil {
t.Fatal(err)
}
return dir
}
......@@ -5,6 +5,7 @@ import (
"github.com/jingweno/gh/utils"
"github.com/jingweno/go-octokit/octokit"
"os"
"path/filepath"
"strings"
)
......@@ -46,3 +47,9 @@ func hasGitRemote(name string) bool {
return false
}
func isEmptyDir(path string) bool {
fullPath := filepath.Join(path, "*")
match, _ := filepath.Glob(fullPath)
return match == nil
}
package commands
import (
"github.com/bmizerany/assert"
"io/ioutil"
"os"
"testing"
)
func TestDirIsNotEmpty(t *testing.T) {
dir := createTempDir(t)
defer os.RemoveAll(dir)
ioutil.TempFile(dir, "gh-utils-test-")
assert.Equal(t, false, isEmptyDir(dir))
}
func TestDirIsEmpty(t *testing.T) {
dir := createTempDir(t)
defer os.RemoveAll(dir)
assert.T(t, isEmptyDir(dir))
}
func createTempDir(t *testing.T) string {
dir, err := ioutil.TempDir("", "gh-utils-test-")
if err != nil {
t.Fatal(err)
}
return dir
}
......@@ -64,9 +64,3 @@ func DirName() (string, error) {
name = strings.Replace(name, " ", "-", -1)
return name, nil
}
func IsEmptyDir(path string) bool {
fullPath := filepath.Join(path, "*")
match, _ := filepath.Glob(fullPath)
return match == nil
}
......@@ -2,8 +2,6 @@ package utils
import (
"github.com/bmizerany/assert"
"io/ioutil"
"os"
"testing"
)
......@@ -18,26 +16,3 @@ func TestSearchBrowserLauncher(t *testing.T) {
func TestConcatPaths(t *testing.T) {
assert.Equal(t, "foo/bar/baz", ConcatPaths("foo", "bar", "baz"))
}
func TestDirIsNotEmpty(t *testing.T) {
dir := createTempDir(t)
defer os.RemoveAll(dir)
ioutil.TempFile(dir, "gh-utils-test-")
assert.Equal(t, false, IsEmptyDir(dir))
}
func TestDirIsEmpty(t *testing.T) {
dir := createTempDir(t)
defer os.RemoveAll(dir)
assert.T(t, IsEmptyDir(dir))
}
func createTempDir(t *testing.T) string {
dir, err := ioutil.TempDir("", "gh-utils-test-")
if err != nil {
t.Fatal(err)
}
return dir
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册