2020-12-16 19:06:34 +00:00
|
|
|
package ci
|
2020-08-15 08:39:03 +00:00
|
|
|
|
|
|
|
import (
|
2020-09-02 11:04:56 +00:00
|
|
|
"bytes"
|
|
|
|
"io"
|
|
|
|
"os"
|
2020-08-15 08:39:03 +00:00
|
|
|
"testing"
|
2020-10-07 21:12:12 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2022-09-19 20:23:45 +00:00
|
|
|
"gitlab.com/gitlab-org/cli/commands/cmdutils"
|
2020-08-15 08:39:03 +00:00
|
|
|
)
|
|
|
|
|
2020-09-29 05:55:34 +00:00
|
|
|
func TestPipelineCmd(t *testing.T) {
|
2020-09-02 11:04:56 +00:00
|
|
|
old := os.Stdout // keep backup of the real stdout
|
|
|
|
r, w, _ := os.Pipe()
|
|
|
|
os.Stdout = w
|
|
|
|
|
2020-12-16 19:06:34 +00:00
|
|
|
assert.Nil(t, NewCmdCI(&cmdutils.Factory{}).Execute())
|
2020-09-02 11:04:56 +00:00
|
|
|
|
|
|
|
outC := make(chan string)
|
|
|
|
// copy the output in a separate goroutine so printing can't block indefinitely
|
|
|
|
go func() {
|
|
|
|
var buf bytes.Buffer
|
2021-01-29 11:36:53 +00:00
|
|
|
_, _ = io.Copy(&buf, r)
|
2020-09-02 11:04:56 +00:00
|
|
|
outC <- buf.String()
|
|
|
|
}()
|
|
|
|
|
|
|
|
// back to normal state
|
|
|
|
w.Close()
|
|
|
|
os.Stdout = old // restoring the real stdout
|
|
|
|
out := <-outC
|
|
|
|
|
2020-12-21 12:21:59 +00:00
|
|
|
assert.Contains(t, out, "Use \"ci [command] --help\" for more information about a command.\n")
|
2020-08-15 12:50:25 +00:00
|
|
|
}
|