github.com/pengwynn/gh@v1.0.1-0.20140118055701-14327ca3942e/commands/apply_test.go (about)

     1  package commands
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/bmizerany/assert"
     6  	"regexp"
     7  	"strings"
     8  	"testing"
     9  )
    10  
    11  func TestTransformApplyArgs(t *testing.T) {
    12  	args := NewArgs([]string{"apply", "https://github.com/jingweno/gh/pull/55"})
    13  	transformApplyArgs(args)
    14  
    15  	cmds := args.Commands()
    16  	assert.Equal(t, 2, len(cmds))
    17  	curlString := fmt.Sprintf("curl -#LA %s https://github.com/jingweno/gh/pull/55.patch -o .+55.patch", fmt.Sprintf("gh %s", Version))
    18  	curlRegexp := regexp.MustCompile(curlString)
    19  	applyString := "git apply"
    20  	assert.T(t, curlRegexp.MatchString(cmds[0].String()))
    21  	assert.T(t, strings.Contains(cmds[1].String(), applyString))
    22  
    23  	args = NewArgs([]string{"apply", "--ignore-whitespace", "https://github.com/jingweno/gh/commit/fdb9921"})
    24  	transformApplyArgs(args)
    25  
    26  	cmds = args.Commands()
    27  	assert.Equal(t, 2, len(cmds))
    28  	curlString = fmt.Sprintf("curl -#LA %s https://github.com/jingweno/gh/commit/fdb9921.patch -o .+fdb9921.patch", fmt.Sprintf("gh %s", Version))
    29  	curlRegexp = regexp.MustCompile(curlString)
    30  	applyString = "git apply --ignore-whitespace"
    31  	assert.T(t, curlRegexp.MatchString(cmds[0].String()))
    32  	assert.T(t, strings.Contains(cmds[1].String(), applyString))
    33  
    34  	args = NewArgs([]string{"apply", "https://gist.github.com/8da7fb575debd88c54cf"})
    35  	transformApplyArgs(args)
    36  
    37  	cmds = args.Commands()
    38  	assert.Equal(t, 2, len(cmds))
    39  	curlString = fmt.Sprintf("curl -#LA %s https://gist.github.com/8da7fb575debd88c54cf.txt -o .+8da7fb575debd88c54cf.txt", fmt.Sprintf("gh %s", Version))
    40  	curlRegexp = regexp.MustCompile(curlString)
    41  	applyString = "git apply"
    42  	assert.T(t, curlRegexp.MatchString(cmds[0].String()))
    43  	assert.T(t, strings.Contains(cmds[1].String(), applyString))
    44  }