Some checks are pending
Docs Deploy / build_and_deploy (push) Waiting to run
Generate Docs / cli (push) Waiting to run
Generate Config Doc / cli (push) Waiting to run
Go formatting / go-formatting (push) Waiting to run
Check links / markdown-link-check (push) Waiting to run
Integration / pre-test (push) Waiting to run
Integration / test on (push) Blocked by required conditions
Integration / status (push) Blocked by required conditions
Lint / Lint Go code (push) Waiting to run
Test / test (ubuntu-latest) (push) Waiting to run
56 lines
1.2 KiB
Go
56 lines
1.2 KiB
Go
package ignitecmd
|
|
|
|
import (
|
|
"bytes"
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestShouldRunServeInDaemonMode(t *testing.T) {
|
|
cmd := NewChainServe()
|
|
|
|
require.NoError(t, cmd.Flags().Set(flagOutputFile, "/tmp/serve.log"))
|
|
require.True(t, shouldRunServeInDaemonMode(cmd))
|
|
}
|
|
|
|
func TestShouldRunServeInDaemonModeNoTerminal(t *testing.T) {
|
|
cmd := NewChainServe()
|
|
cmd.SetIn(bytes.NewBufferString(""))
|
|
cmd.SetOut(bytes.NewBuffer(nil))
|
|
|
|
require.True(t, shouldRunServeInDaemonMode(cmd))
|
|
}
|
|
|
|
func TestShouldRunServeInDaemonModeInteractiveTerminal(t *testing.T) {
|
|
cmd := NewChainServe()
|
|
cmd.SetIn(os.Stdin)
|
|
cmd.SetOut(os.Stdout)
|
|
|
|
originalIsTerminal := isTerminal
|
|
t.Cleanup(func() {
|
|
isTerminal = originalIsTerminal
|
|
})
|
|
isTerminal = func(_ int) bool { return true }
|
|
|
|
require.False(t, shouldRunServeInDaemonMode(cmd))
|
|
}
|
|
|
|
func TestShouldRunServeInDaemonModeMixedTerminal(t *testing.T) {
|
|
cmd := NewChainServe()
|
|
cmd.SetIn(os.Stdin)
|
|
cmd.SetOut(os.Stdout)
|
|
|
|
originalIsTerminal := isTerminal
|
|
t.Cleanup(func() {
|
|
isTerminal = originalIsTerminal
|
|
})
|
|
calls := 0
|
|
isTerminal = func(_ int) bool {
|
|
calls++
|
|
return calls == 1
|
|
}
|
|
|
|
require.True(t, shouldRunServeInDaemonMode(cmd))
|
|
}
|