github.com/jingweno/gh@v2.1.1-0.20221007190738-04a7985fa9a1+incompatible/commands/utils_test.go (about)

     1  package commands
     2  
     3  import (
     4  	"io/ioutil"
     5  	"os"
     6  	"testing"
     7  
     8  	"github.com/bmizerany/assert"
     9  )
    10  
    11  func TestGetTitleAndBodyFromFlags(t *testing.T) {
    12  	s := "just needs raven\n\nnow it works"
    13  	title, body, err := getTitleAndBodyFromFlags(s, "")
    14  
    15  	assert.Equal(t, nil, err)
    16  	assert.Equal(t, "just needs raven", title)
    17  	assert.Equal(t, "now it works", body)
    18  
    19  	s = "just needs raven\\n\\nnow it works"
    20  	title, body, err = getTitleAndBodyFromFlags(s, "")
    21  
    22  	assert.Equal(t, nil, err)
    23  	assert.Equal(t, "just needs raven", title)
    24  	assert.Equal(t, "now it works", body)
    25  }
    26  
    27  func TestDirIsNotEmpty(t *testing.T) {
    28  	dir := createTempDir(t)
    29  	defer os.RemoveAll(dir)
    30  	ioutil.TempFile(dir, "gh-utils-test-")
    31  
    32  	assert.T(t, !isEmptyDir(dir))
    33  }
    34  
    35  func TestDirIsEmpty(t *testing.T) {
    36  	dir := createTempDir(t)
    37  	defer os.RemoveAll(dir)
    38  
    39  	assert.T(t, isEmptyDir(dir))
    40  }
    41  
    42  func createTempDir(t *testing.T) string {
    43  	dir, err := ioutil.TempDir("", "gh-utils-test-")
    44  	if err != nil {
    45  		t.Fatal(err)
    46  	}
    47  	return dir
    48  }