github.com/zaquestion/lab@v0.25.1/cmd/mr_edit_test.go (about) 1 package cmd 2 3 import ( 4 "os/exec" 5 "strings" 6 "testing" 7 8 "github.com/stretchr/testify/require" 9 ) 10 11 func MREditCmdTestCreateMR(t *testing.T, dir string) string { 12 git := exec.Command("git", "checkout", "-b", "local/mrtest", "origin/mrtest") 13 git.Dir = dir 14 g, err := git.CombinedOutput() 15 if err != nil { 16 t.Log(string(g)) 17 t.Fatal(err) 18 } 19 20 cmd := exec.Command(labBinaryPath, "mr", "create", "lab-testing", "-m", "mr title", "-m", "mr description") 21 cmd.Dir = dir 22 23 b, err := cmd.CombinedOutput() 24 if err != nil { 25 t.Fatal(err) 26 } 27 28 i := strings.Index(string(b), "/diffs\n") 29 mrID := strings.TrimPrefix(string(b)[:i], "https://gitlab.com/lab-testing/test/-/merge_requests/") 30 return mrID 31 } 32 33 func Test_MRNoteDelete(t *testing.T) { 34 repo := copyTestRepo(t) 35 36 mrNum := MREditCmdTestCreateMR(t, repo) 37 38 // add just a note "DELETED 1" 39 cmd := exec.Command(labBinaryPath, "mr", "note", "lab-testing", mrNum, "-m", "DELETED 1") 40 cmd.Dir = repo 41 42 weburl, err := cmd.CombinedOutput() 43 if err != nil { 44 t.Log(string(weburl)) 45 t.Fatal(err) 46 } 47 noteIDs := strings.Split(string(weburl), "\n") 48 noteID := strings.Split(noteIDs[0], "#note_")[1] 49 deletedNote := mrNum + ":" + noteID 50 51 // add another note "REPLY 2" 52 cmd = exec.Command(labBinaryPath, "mr", "note", "lab-testing", mrNum, "-m", "REPLY 2") 53 cmd.Dir = repo 54 55 weburl, err = cmd.CombinedOutput() 56 if err != nil { 57 t.Log(string(weburl)) 58 t.Fatal(err) 59 } 60 noteIDs = strings.Split(string(weburl), "\n") 61 noteID = strings.Split(noteIDs[0], "#note_")[1] 62 replyNote := mrNum + ":" + noteID 63 64 // reply to the "REPLY 2" comment with a note to create a discussion "DELETED 2" 65 cmd = exec.Command(labBinaryPath, "mr", "reply", "lab-testing", replyNote, "-m", "DELETED 2") 66 cmd.Dir = repo 67 68 weburl, err = cmd.CombinedOutput() 69 if err != nil { 70 t.Log(string(weburl)) 71 t.Fatal(err) 72 } 73 noteIDs = strings.Split(string(weburl), "\n") 74 noteID = strings.Split(noteIDs[0], "#note_")[1] 75 deletedDiscussion := mrNum + ":" + noteID 76 77 // reply to the comment with a second comment "DISCUSSION 1" 78 cmd = exec.Command(labBinaryPath, "mr", "reply", "lab-testing", replyNote, "-m", "DISCUSSION 1") 79 cmd.Dir = repo 80 81 weburl, err = cmd.CombinedOutput() 82 if err != nil { 83 t.Log(string(weburl)) 84 t.Fatal(err) 85 } 86 87 // delete the first note 88 cmd = exec.Command(labBinaryPath, "mr", "edit", "lab-testing", deletedNote, "--delete-note") 89 cmd.Dir = repo 90 91 weburl, err = cmd.CombinedOutput() 92 if err != nil { 93 t.Log(string(weburl)) 94 t.Fatal(err) 95 } 96 97 // delete the first discussion reply 98 cmd = exec.Command(labBinaryPath, "mr", "edit", "lab-testing", deletedDiscussion, "--delete-note") 99 cmd.Dir = repo 100 101 weburl, err = cmd.CombinedOutput() 102 if err != nil { 103 t.Log(string(weburl)) 104 t.Fatal(err) 105 } 106 107 // show the updated mr and comments 108 cmd = exec.Command(labBinaryPath, "mr", "show", "lab-testing", mrNum, "--comments") 109 cmd.Dir = repo 110 111 b, err := cmd.CombinedOutput() 112 if err != nil { 113 t.Fatal(err) 114 } 115 mrShowOutput := string(b) 116 117 git := exec.Command(labBinaryPath, "mr", "close", "lab-testing", mrNum) 118 git.Dir = repo 119 g, err := git.CombinedOutput() 120 if err != nil { 121 t.Log(string(g)) 122 t.Fatal(err) 123 } 124 125 // lab show should not contain "DELETED" notes 126 require.NotContains(t, mrShowOutput, "DELETED 1") 127 require.NotContains(t, mrShowOutput, "DELETED 2") 128 // lab show should contain the other notes and disucssion 129 require.Contains(t, mrShowOutput, "REPLY 2") 130 require.Contains(t, mrShowOutput, "DISCUSSION 1") 131 }