@@ -1167,3 +1167,63 @@ func TestOptionsBeforeExec(t *testing.T) {
11671167 t .Error ("exec cmd option not applied" )
11681168 }
11691169}
1170+
1171+ func TestCmdLineBufferIncrease (t * testing.T ) {
1172+ lineContent := cmd .DEFAULT_LINE_BUFFER_SIZE * 2
1173+ longLine := make ([]byte , lineContent ) // "AAA..."
1174+ for i := 0 ; i < lineContent ; i ++ {
1175+ longLine [i ] = 'A'
1176+ }
1177+
1178+ tmpfile , err := ioutil .TempFile ("" , "cmd.TestCmdLineBufferIncrease" )
1179+ if err != nil {
1180+ t .Fatal (err )
1181+ }
1182+ t .Cleanup (func () {
1183+ os .Remove (tmpfile .Name ())
1184+ })
1185+ if _ , err := tmpfile .Write (longLine ); err != nil {
1186+ t .Fatal (err )
1187+ }
1188+ if err := tmpfile .Close (); err != nil {
1189+ t .Fatal (err )
1190+ }
1191+
1192+ timeout := time .After (10 * time .Second ) // test timeout
1193+
1194+ catStdout := cmd .NewCmdOptions (cmd.Options {
1195+ Streaming : true ,
1196+ LineBufferSize : cmd .DEFAULT_LINE_BUFFER_SIZE * 2 ,
1197+ }, "./test/cat" , tmpfile .Name (), "1" )
1198+
1199+ catStdoutStatus := catStdout .Start ()
1200+
1201+ select {
1202+ case curLine := <- catStdout .Stdout :
1203+ t .Logf ("got stdout bytes: %d" , len (curLine ))
1204+ if len (curLine ) <= cmd .DEFAULT_LINE_BUFFER_SIZE {
1205+ t .Error ("Unable to read more than default line buffer from stdout" )
1206+ }
1207+ case <- timeout :
1208+ t .Fatal ("timeout reading streaming output" )
1209+ }
1210+ <- catStdoutStatus
1211+
1212+ catStderr := cmd .NewCmdOptions (cmd.Options {
1213+ Streaming : true ,
1214+ LineBufferSize : cmd .DEFAULT_LINE_BUFFER_SIZE * 2 ,
1215+ }, "./test/cat" , tmpfile .Name (), "2" )
1216+
1217+ catStderrStatus := catStderr .Start ()
1218+
1219+ select {
1220+ case curLine := <- catStderr .Stderr :
1221+ t .Logf ("got stderr bytes: %d" , len (curLine ))
1222+ if len (curLine ) <= cmd .DEFAULT_LINE_BUFFER_SIZE {
1223+ t .Error ("Unable to read more than default line buffer from stderr" )
1224+ }
1225+ case <- timeout :
1226+ t .Fatal ("timeout reading streaming output" )
1227+ }
1228+ <- catStderrStatus
1229+ }
0 commit comments