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
41 lines
736 B
Go
41 lines
736 B
Go
package markdownviewer
|
|
|
|
import (
|
|
"os"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestConfigReturnsErrorWhenStdoutIsNotTTY(t *testing.T) {
|
|
tempStdout := setNonTTYStdout(t)
|
|
|
|
_, err := config(t.TempDir())
|
|
require.Error(t, err)
|
|
|
|
require.NoError(t, tempStdout.Close())
|
|
}
|
|
|
|
func TestViewReturnsConfigErrorWhenStdoutIsNotTTY(t *testing.T) {
|
|
tempStdout := setNonTTYStdout(t)
|
|
|
|
err := View(t.TempDir())
|
|
require.Error(t, err)
|
|
|
|
require.NoError(t, tempStdout.Close())
|
|
}
|
|
|
|
func setNonTTYStdout(t *testing.T) *os.File {
|
|
t.Helper()
|
|
|
|
file, err := os.CreateTemp(t.TempDir(), "stdout-*")
|
|
require.NoError(t, err)
|
|
|
|
originalStdout := os.Stdout
|
|
os.Stdout = file
|
|
t.Cleanup(func() {
|
|
os.Stdout = originalStdout
|
|
})
|
|
|
|
return file
|
|
}
|