github.com/zaquestion/lab@v0.25.1/cmd/mr_browse_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_mrBrowseWithParameter(t *testing.T) { 11 oldBrowse := browse 12 defer func() { browse = oldBrowse }() 13 14 browse = func(url string) error { 15 require.Equal(t, "https://gitlab.com/zaquestion/test/merge_requests/1", url) 16 return nil 17 } 18 19 mrBrowseCmd.Run(nil, []string{"1"}) 20 } 21 22 func Test_mrBrowseCurrent(t *testing.T) { 23 git := exec.Command("git", "checkout", "mrtest2") 24 b, err := git.CombinedOutput() 25 if err != nil { 26 t.Log(string(b)) 27 t.Fatal(err) 28 } 29 defer func() { 30 git := exec.Command("git", "checkout", "master") 31 b, err := git.CombinedOutput() 32 if err != nil { 33 t.Log(string(b)) 34 t.Fatal(err) 35 } 36 }() 37 38 oldBrowse := browse 39 defer func() { browse = oldBrowse }() 40 41 browse = func(url string) error { 42 require.Equal(t, "https://gitlab.com/zaquestion/test/merge_requests/3", url) 43 return nil 44 } 45 46 mrBrowseCmd.Run(nil, nil) 47 }