@@ -15,6 +15,7 @@ import (
1515 "os/exec"
1616 "path/filepath"
1717 "runtime"
18+ "strconv"
1819 "strings"
1920 "testing"
2021 "time"
@@ -92,6 +93,8 @@ func TestScript(t *testing.T) {
9293 "new-webhook" : cmdNewWebhook ,
9394 "waitforserver" : cmdWaitforserver ,
9495 "stopserver" : cmdStopserver ,
96+ "ui" : cmdUI (admin1 .Signer ()),
97+ "uui" : cmdUI (user1 .Signer ()),
9598 },
9699 Setup : func (e * testscript.Env ) error {
97100 // Add binPath to PATH
@@ -120,6 +123,9 @@ func TestScript(t *testing.T) {
120123 // This is used to set up test specific configuration and http endpoints
121124 e .Setenv ("SOFT_SERVE_TESTRUN" , "1" )
122125
126+ // This will disable the default lipgloss renderer colors
127+ e .Setenv ("SOFT_SERVE_NO_COLOR" , "1" )
128+
123129 // Soft Serve debug environment variables
124130 for _ , env := range []string {
125131 "SOFT_SERVE_DEBUG" ,
@@ -199,6 +205,64 @@ func cmdSoft(key ssh.Signer) func(ts *testscript.TestScript, neg bool, args []st
199205 }
200206}
201207
208+ func cmdUI (key ssh.Signer ) func (ts * testscript.TestScript , neg bool , args []string ) {
209+ return func (ts * testscript.TestScript , neg bool , args []string ) {
210+ if len (args ) < 1 {
211+ ts .Fatalf ("usage: ui <quoted string input>" )
212+ return
213+ }
214+
215+ cli , err := ssh .Dial (
216+ "tcp" ,
217+ net .JoinHostPort ("localhost" , ts .Getenv ("SSH_PORT" )),
218+ & ssh.ClientConfig {
219+ User : "git" ,
220+ Auth : []ssh.AuthMethod {ssh .PublicKeys (key )},
221+ HostKeyCallback : ssh .InsecureIgnoreHostKey (),
222+ },
223+ )
224+ check (ts , err , neg )
225+ defer cli .Close ()
226+
227+ sess , err := cli .NewSession ()
228+ check (ts , err , neg )
229+ defer sess .Close ()
230+
231+ // XXX: this is a hack to make the UI tests work
232+ // cmp command always complains about an extra newline
233+ // in the output
234+ defer ts .Stdout ().Write ([]byte ("\n " ))
235+
236+ sess .Stdout = ts .Stdout ()
237+ sess .Stderr = ts .Stderr ()
238+
239+ stdin , err := sess .StdinPipe ()
240+ check (ts , err , neg )
241+
242+ in , err := strconv .Unquote (args [0 ])
243+ check (ts , err , neg )
244+ reader := strings .NewReader (in )
245+ go func () {
246+ defer stdin .Close ()
247+ for {
248+ r , _ , err := reader .ReadRune ()
249+ if err == io .EOF {
250+ break
251+ }
252+ check (ts , err , neg )
253+ stdin .Write ([]byte (string (r ))) // nolint: errcheck
254+
255+ // Wait for the UI to process the input
256+ time .Sleep (100 * time .Millisecond )
257+ }
258+ }()
259+
260+ err = sess .RequestPty ("dumb" , 40 , 80 , ssh.TerminalModes {})
261+ check (ts , err , neg )
262+ check (ts , sess .Run ("" ), neg )
263+ }
264+ }
265+
202266// P.S. Windows sucks!
203267func cmdDos2Unix (ts * testscript.TestScript , neg bool , args []string ) {
204268 if neg {
0 commit comments