github.com/scorpionis/hub@v2.2.1+incompatible/commands/utils_test.go (about)

     1  package commands
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"testing"
     7  
     8  	"github.com/github/hub/Godeps/_workspace/src/github.com/bmizerany/assert"
     9  )
    10  
    11  func TestReadMsg(t *testing.T) {
    12  	title, body := readMsg("")
    13  	assert.Equal(t, "", title)
    14  	assert.Equal(t, "", body)
    15  
    16  	title, body = readMsg("my pull title")
    17  	assert.Equal(t, "my pull title", title)
    18  	assert.Equal(t, "", body)
    19  
    20  	title, body = readMsg("my pull title\n\nmy description\n\nanother line")
    21  	assert.Equal(t, "my pull title", title)
    22  	assert.Equal(t, "my description\n\nanother line", body)
    23  
    24  	title, body = readMsg("my pull title\r\n\r\nmy description\r\n\r\nanother line")
    25  	assert.Equal(t, "my pull title", title)
    26  	assert.Equal(t, "my description\r\n\r\nanother line", body)
    27  }
    28  
    29  func TestDirIsNotEmpty(t *testing.T) {
    30  	dir := createTempDir(t)
    31  	defer os.RemoveAll(dir)
    32  	ioutil.TempFile(dir, "gh-utils-test-")
    33  
    34  	assert.T(t, !isEmptyDir(dir))
    35  }
    36  
    37  func TestDirIsEmpty(t *testing.T) {
    38  	dir := createTempDir(t)
    39  	defer os.RemoveAll(dir)
    40  
    41  	assert.T(t, isEmptyDir(dir))
    42  }
    43  
    44  func createTempDir(t *testing.T) string {
    45  	dir, err := ioutil.TempDir("", "gh-utils-test-")
    46  	if err != nil {
    47  		t.Fatal(err)
    48  	}
    49  	return dir
    50  }