github.com/ianfoo/lab@v0.9.5-0.20180123060006-5ed79f2ccfc7/cmd/fork_test.go (about)

     1  package cmd
     2  
     3  import (
     4  	"os/exec"
     5  	"testing"
     6  
     7  	"github.com/stretchr/testify/require"
     8  )
     9  
    10  func Test_fork(t *testing.T) {
    11  	t.Parallel()
    12  	repo := copyTestRepo(t)
    13  	// remove the remote so we can test adding it back
    14  	// NOTE: we aren't actually going to test that forks are created on
    15  	// GitLab, just that lab behaves correctly when a fork exists.
    16  	cmd := exec.Command("git", "remote", "remove", "lab-testing")
    17  	cmd.Dir = repo
    18  	err := cmd.Run()
    19  	if err != nil {
    20  		t.Fatal(err)
    21  	}
    22  
    23  	cmd = exec.Command("../lab_bin", "fork")
    24  	cmd.Dir = repo
    25  
    26  	b, err := cmd.CombinedOutput()
    27  	if err != nil {
    28  		t.Fatal(err)
    29  	}
    30  
    31  	out := string(b)
    32  
    33  	require.Contains(t, out, "From gitlab.com:lab-testing/test")
    34  	require.Contains(t, out, "new remote: lab-testing")
    35  
    36  	cmd = exec.Command("git", "remote", "-v")
    37  	cmd.Dir = repo
    38  
    39  	b, err = cmd.CombinedOutput()
    40  	if err != nil {
    41  		t.Fatal(err)
    42  	}
    43  	require.Contains(t, string(b), "lab-testing")
    44  }